使用http DELETE删除资源 [英] Deleting a resource using http DELETE

查看:631
本文介绍了使用http DELETE删除资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,鉴于Http中的DELETE动词是幂等的,当我发出以下请求时,第二个(或第三个,或第四个等等)会发生什么?

So, given that the DELETE verb in Http is idempotent, when I issue the following request, what should happen the second (or third, or fourth, etc...)?

DELETE /person/123

第一个时间,资源被删除,我返回204(成功,没有内容)。我应该在后续调用或404(未找到)上返回204吗?

The first time, the resource is deleted and I return a 204 (successful, no content). Should I return a 204 on subsequent calls or a 404 (not found)?

推荐答案

因为无状态系统中的HTTP请求应该是独立的,一个请求的结果不应该依赖于先前的请求。考虑如果两个用户同时在同一资源上执行DELETE会发生什么。第二个获取404的请求是有意义的。如果一个用户发出两个请求,情况也应该如此。

As HTTP requests in a stateless system should be independent, the results of one request should not be dependent on a previous request. Consider what should happen if two users did a DELETE on the same resource simultaneously. It makes sense for the second request to get a 404. The same should be true if one user makes two requests.

我猜是让DELETE返回两个不同的响应不觉得你是幂等的。我认为将幂等请求视为使系统处于相同状态,而不一定具有相同的响应是有用的。因此,无论您是删除现有资源,还是尝试删除不存在的资源,服务器资源状态都是相同的。

I am guessing that having DELETE return two different responses does not feel idempotent to you. I find it useful to think of idempotent requests as leaving the system in the same state, not necessarily having the same response. So regardless of whether you DELETE an existing resource, or attempt to DELETE a resource that does not exist, the server resource state is the same.

这篇关于使用http DELETE删除资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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