什么情况下可以使用HTTP DELETE停用的记录? [英] Is it okay to use an HTTP DELETE to deactivate a record?

查看:215
本文介绍了什么情况下可以使用HTTP DELETE停用的记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建一个RESTful API命令停用用户记录。它是犹太用delete要做到这一点还是应该这是一个PUT,因为记录被更新为已停用状态?或者是它只是一个品味的问题?

I'm building a RESTful API command to deactivate a user record. Is it kosher to use DELETE to do this or should this be a PUT, since the record is being updated to "deactivated" status? Or is it just a matter of taste?

推荐答案

的语义删除意味着你实际上是摆脱的对象。你在做什么在这里好像对象状态的修改。在这种情况下, PUT PATCH 将更为合适。

The semantics of DELETE means that you are actually getting rid of the object. What you're doing here seems like a modification of the object's state. In this case a PUT or PATCH would be more appropriate.

这是更好地坚持你使用(在这种情况下,HTTP动词)的统一接口的语义。如果这些匹配到你实际上你的应用程序中做什么,再有就是减少混乱。另外,如果你决定以后,一个删除实际上应该删除的记录,而不是仅仅将其标记为无效?现在,你已经改变了你的API的行为。另外,如果你使用删除,你基本上遵循,这是很好的一个API最惊喜的原则。最好是有一个删除实际上做了删除,而不是仅仅pretending这样做。

It is better to stick with the semantics of uniform interface that you're using (in this case, HTTP verbs). If those match up to what you're actually doing within your app, then there is less confusion. Also, what if you decide later that a DELETE should actually remove a record instead of just marking it "inactive"? Now you've changed the behavior of your API. Also, if you're using DELETE, you're essentially following the "principle of least surprise", which is good for an API. It's better to have a DELETE actually do a delete, rather than just pretending to do so.

在另一方面,它是完美的罚款从一个位置删除的记录和其他移动(从一个表到另一个,例如),如果事实证明,你需要保持数据历史的目的。在这种情况下,这个纪录应该只是依然无法得到未来经营(即 GET 上的资源应该返回一个 404 )。

On the other hand it is perfectly fine to remove the record from one location and move it elsewhere (from one table to another, for example) if it turns out that you are required to keep the data for historical purposes. In this case, that record should just remain unavailable to future operations (i.e., a GET on the resource should return a 404).

这篇关于什么情况下可以使用HTTP DELETE停用的记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆