知识卡片
外部枚举保留演进空间
内部布尔开关不宜直接限定外部业务状态。把它表达成有名字的选项,并由接口层映射到内部布尔值,可为未来增加业务状态留出空间。
书中HAL-FORMS示例先提供options.inline:["No","Yes"],以后加入pending只需扩展所发布的选项;客户端应按运行时可选项处理,而非假定永远只有两种。这个做法是外部动作契约的演进策略,不意味着任意老客户端都自动理解新状态的业务后果。
关联:[[动作契约遮蔽内部流程]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 超媒体服务 · 查看原书依据
Now, code within the API can translate the "Yes" / "No" values to true or false before calling the underlying service. In addition, if future changes to the service result in a possible pending status, the options element of the form can be updated without any other changes to the API.
参考来源
- 位置:《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.4)
- 结论依据:原文从布尔接口改为HAL-FORMS选项,说明加入pending时映射层与外部选项的演进。
- 原始内容:Now, code within the API can translate the "Yes" / "No" values to true or false before calling the underlying service. In addition, if future changes to the service result in a possible pending status, the options element of the form can be updated without any other changes to the API.