知识卡片
条件PUT保护写入
针对[[扣款超时结果不明]]代表的不确定写入问题,书中优先采用客户端确定资源URI的条件PUT设计:创建时用If-None-Match: *,更新时用If-Match携带上次ETag,前置条件不满足返回412。重试仍指向同一资源并受版本条件保护,不能仅把增量扣款POST改名为PUT就宣称幂等;操作本身还须具备可重复语义。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 超媒体接口设计 · 查看原书依据
Here, the HTTP request is marked with the If-Match: header that contains the entity tag (or ETag) that identifies the exact version of the resource at /person/q1w2e3 you wish to update. If the ETag at that URL doesn’t match the one in the request (e.g., if the resource doesn’t exist or has been updated by someone else lately), then the HTTP PUT will be rejected with an HTTP 412 Precondition Failed response instead.
参考来源
- 位置:《RESTful Web API Patterns and Practices Cookbook Connecting and Orchestrating Microservices and Distributed Data (Mike Amundsen)》第03章《超媒体接口设计》(来源项目 book-sources;源文件:extracted/RESTful Web API Patterns and Practices Cookbook Connecting and Orchestrating Microservices and Distributed Data (Mike Amundsen)/_epub-src/OEBPS/ch03.xhtml;小节:3.6)
- 结论依据:原文以针对[[扣款超时结果不明]]代表的不确定写入问题,书中优先采用客户端确定资源URI的条件PUT设计:创建时用If-None-Match: *,更新时用If-Match携带上次ETag,前置条件不满足返回412的机制或场景为依据;同小节余文补充本卡所列条件,按2022年原书语境整理。
- 原始内容:Here, the HTTP request is marked with the If-Match: header that contains the entity tag (or ETag) that identifies the exact version of the resource at /person/q1w2e3 you wish to update. If the ETag at that URL doesn’t match the one in the request (e.g., if the resource doesn’t exist or has been updated by someone else lately), then the HTTP PUT will be rejected with an HTTP 412 Precondition Failed response instead.