DELETE 应该是幂等的。
如果我删除 http://example.com/account/123它将删除该帐户。
如果我再做一次,我是否会收到 404,因为该帐户已不存在?如果我试图删除一个从未存在过的帐户怎么办?
最佳答案
幂等性是指请求完成后系统的状态
在所有情况下(错误问题除外 - 见下文),该帐户不再存在。
来自 here
"Methods can also have the property of "idempotence" in that (aside from error or expiration issues) the side-effects of N > 0 identical requests is the same as for a single request. The methods GET, HEAD, PUT and DELETE share this property. Also, the methods OPTIONS and TRACE SHOULD NOT have side effects, and so are inherently idempotent. "
关键是 N > 0 个相同请求的副作用与单个请求相同。
您期望状态代码会有所不同是正确的,但这不会影响幂等性的核心概念 - 您可以多次发送请求,而无需对服务器状态进行其他更改。
关于http - REST DELETE 真的是幂等的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4088350/