REST DELETE 真的是幂等的吗? [英] Is REST DELETE really idempotent?

查看:34
本文介绍了REST DELETE 真的是幂等的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DELETE 应该是幂等的.

DELETE is supposed to be idempotent.

如果我删除 http://example.com/account/123,它将删除该帐户.

If I DELETE http://example.com/account/123 it's going to delete the account.

如果我再做一次,我会期待 404,因为该帐户不再存在吗?如果我尝试删除一个从未存在过的帐户怎么办?

If I do it again would I expect a 404, since the account no longer exists? What if I attempt to DELETE an account that has never existed?

推荐答案

幂等是指请求完成后系统的状态


在所有情况下(除了错误问题 - 见下文),该帐户都不再存在.

In all cases (apart from the error issues - see below), the account no longer exists.

来自这里

"方法也可以具有其中的幂等性"(除了错误或过期问题)N > 0 相同的副作用请求与单个请求相同要求.方法 GET、HEAD、PUT和 DELETE 共享此属性.还,方法 OPTIONS 和 TRACE 应该没有副作用,所以是本质上是幂等的."

"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 个相同请求的副作用与单个请求相同.

您期望状态代码会有所不同是正确的,但这不会影响幂等性的核心概念 - 您可以多次发送请求,而无需额外更改服务器状态.

You would be correct to expect that the status code would be different but this does not affect the core concept of idempotency - you can send the request more than once without additional changes to the state of the server.

这篇关于REST DELETE 真的是幂等的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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