知识卡片

问题卡 · 2509.c.1

安全重试有两个层次

理解等级:中级

可重试既要求网络方法的约定,也要求操作消息的业务语义。GET、PUT、DELETE具备幂等方法语义;实际更新还应使用替换值及必要验证条件,避免“增加1”或“涨5%”式重复累加。幂等表示重复作用不再增加预期状态效果,并不保证每次响应码相同;条件更新重放也可能因条件已改变而被拒绝。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 超媒体接口设计 · 查看原书依据

      The second thing you can do is design write operations themselves to support idempotences. This often means not using patterns like increments (“add one to each total”) or computing percentages (“increase the sale price by 5%”) and instead using replacement values and validators (“if the current price is 100, change it to 105”). By relying on HTTP’s PUT to update a resource and by designing the body of updates to use replacement rather than increment, you can increase the repeatability of the write operations for your service interface.

    参考来源

    - 位置:《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.8) - 结论依据:原文以可重试既要求网络方法的约定,也要求操作消息的业务语义的机制或场景为依据;同小节余文补充本卡所列条件,按2022年原书语境整理。 - 原始内容:The second thing you can do is design write operations themselves to support idempotences. This often means not using patterns like increments (“add one to each total”) or computing percentages (“increase the sale price by 5%”) and instead using replacement values and validators (“if the current price is 100, change it to 105”). By relying on HTTP’s PUT to update a resource and by designing the body of updates to use replacement rather than increment, you can increase the repeatability of the write operations for your service interface.