知识卡片
用幂等创建消除重复写入
为同一次资源创建预分配唯一URL,使用PUT表达目标资源状态;重试仍针对同一资源,避免把每次重发解释为新动作。创建可带If-None-Match: *,更新可带先前ETag的If-Match,由服务原子判断前置条件。
它对应[[转账响应丢失的歧义]]:不再因重发另建一条转账记录。业务处理仍须保证该资源对应的转账只执行一次;HTTP方法名称本身不会自动去重副作用。重发收到前置条件失败时也要识别可能已完成,不能简单断言原操作失败。书中状态码与ETag示例存在可疑写法,未复制为协议规范。
关联:[[客户端预分配资源标识]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 超媒体服务 · 查看原书依据
The key to the lost response solution is to always support an idempotent HTTP method (PUT) to write data to the server. When you want client applications to create new resources, instruct them to use the PUT method, supply a complete URL, and include the If-None-Match header with a value of "*".
参考来源
- 位置:《RESTful Web API Patterns and Practices Cookbook》第5章《Hypermedia Services》(来源项目book-sources:extracted/RESTful Web API Patterns and Practices Cookbook Connecting and Orchestrating Microservices and Distributed Data (Mike Amundsen)/_epub-src/OEBPS/ch05.xhtml,配方5.15)
- 结论依据:原文以完整资源URL、PUT、If-None-Match及If-Match提出可重复的创建与更新;副作用需正确实现是其成立边界。
- 原始内容:The key to the lost response solution is to always support an idempotent HTTP method (PUT) to write data to the server. When you want client applications to create new resources, instruct them to use the PUT method, supply a complete URL, and include the If-None-Match header with a value of "*".