gpt4 book ai didi

http - HTTP PUT 上下文中幂等性的含义?

转载 作者:塔克拉玛干 更新时间:2023-11-01 19:09:22 24 4
gpt4 key购买 nike

this presentation on REST (时间戳 17:00-18:45),演讲者说 HTTP PUT 必须包含资源的所有属性,而不是用于部分更新。这在 HTTP 中是必需的,否则它不是幂等的。

他对幂等性的定义是(这听起来很合理):

idempotent is any operation that can be performed once or multiple times and result in the same server state

但是,他接着举了一个例子(释义):

Request A: I use a PUT to update only the name property of a resource.

Request B: I use a PUT to update only the description.

In between A and B another client could specify the name, then after request B, the resource has the other client's name, and my description. Because the server state isn't the same after request A and B, that's not an idempotent operation.

我不确定这种解释:对我来说,幂等性只告诉您当您连续多次运行相同 操作时会发生什么。在上面的示例中,请求 A 和 B 是两个不同的操作,因此没有理由认为运行 A 然后运行 ​​B 应该有任何特殊保证;特别是,没有理由认为它们应该一起构成一个原子操作。

多次运行请求 A 会产生与运行一次相同的效果(对于 B 也是如此),所以我认为它是幂等的(即使由于其他原因这是对 PUT 的错误使用).

我的理解有误吗?

(注意:这是一个关于幂等性含义的问题,而不是PUT的适当使用)。

最佳答案

你是对的;部分更新可以是幂等的。

这并没有改变 PUT 不用于部分更新的事实;如果您需要部分更新,您应该使用 PATCH。

关于http - HTTP PUT 上下文中幂等性的含义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22100740/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com