知识卡片
保留直接HTTP能力
SDK没有覆盖所需能力,或把多次远程调用藏在一个方法里时,客户端容易失去解决问题的空间。
SDK可以提供便利,但客户端仍应能直接构造HTTP请求,并检查状态码、响应头及正文。否则SDK未覆盖的新用法会变成调用障碍。
可把URL、方法、头、查询、正文和回调交给统一HTTP辅助库,回调同时取得响应与状态。封装须让调用者看得见网络成本:一次assignUserWorkTickets可能隐藏多次串行或并行请求,不能把远程调用误当作普通本地方法。
关联:[[逐步外置服务地址]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 超媒体客户端 · 查看原书依据
The best way to create API client applications that are both effective and nimble is to make sure they are “protocol-aware”—that they can, when needed, speak directly to a service using the HTTP protocol (or whatever protocol the service is using). To do that, even when your client app takes advantage of SDKs and helper libraries, you should make sure your client app also knows how to “speak HTTP” directly.
参考来源
- 位置:《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.2)
- 结论依据:原文要求保留直接HTTP能力,并用隐藏多次网络调用的SDK方法说明封装的可见性问题。
- 原始内容:The best way to create API client applications that are both effective and nimble is to make sure they are “protocol-aware”—that they can, when needed, speak directly to a service using the HTTP protocol (or whatever protocol the service is using). To do that, even when your client app takes advantage of SDKs and helper libraries, you should make sure your client app also knows how to “speak HTTP” directly.