知识卡片
逐步外置服务地址
服务地址变化时,先把散落的URL改为命名变量,再移到可更新的配置文件;最理想的是只配置一个稳定起点,从响应的id/name/rel/tag寻找后续URL。
典型调用由http.open("GET", serviceURLs.list)读取配置,而非把地址写进业务逻辑。URI模板须双方采用一致展开规则,书中建议RFC 6570。配置只是降级办法:服务迁址仍须通知维护者更新,存在同步滞后;超媒体则把地址更新交给运行时消息。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 超媒体客户端 · 查看原书依据
The best way to limit the impact of service URL changes in your client applications is to “abstract away” the actual URL values: Use named URL variables. First, you should code your client so that any URL reference within the application is a named variable, not an actual URL. This is a similar pattern to how you can “localize” your client application for a single language (French, Arabic, Korean, etc.).
参考来源
- 位置:《RESTful Web API Patterns and Practices Cookbook》第4章《Hypermedia Clients》(来源项目book-sources:extracted/RESTful Web API Patterns and Practices Cookbook Connecting and Orchestrating Microservices and Distributed Data (Mike Amundsen)/_epub-src/OEBPS/ch04.xhtml,配方4.1)
- 结论依据:原文依次给出命名URL变量、外部配置及从响应发现地址,讨论配置更新滞后与URI模板约定。
- 原始内容:The best way to limit the impact of service URL changes in your client applications is to “abstract away” the actual URL values: Use named URL variables. First, you should code your client so that any URL reference within the application is a named variable, not an actual URL. This is a similar pattern to how you can “localize” your client application for a single language (French, Arabic, Korean, etc.).