知识卡片

问题卡 · 3481.g

内容协商的两种选择

理解等级:中级

同一资源支持多个表示格式时,服务与消费者须在运行时决定实际交换哪一种。

主动协商由客户端在Accept列出格式及q偏好,服务用Content-Type告诉最终选择;客户端须检查自己是否真能处理。无法满足时可返回406,不应假设最高q总会被选择。

响应式协商可先返回300及候选链接,由客户端选择后再请求,多一次往返且机器选择细节要双方约定。按格式拆URL能绕开协商,却增加路径维护。书中倾向于设计文档说明、运行时偏好发现与主动协商结合。

关联:[[发布可缓存偏好资源]]。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 超媒体服务 · 查看原书依据

      An alternative to proactive content negotiation by the service is reactive content negotiation (RCN). In RCN, the service sends the client a list of possible representation formats, and the client is expected to select the preferred format from the list and make the request a second time, specifying which response format has been selected. This puts the power of selection squarely in the hands of the client application but also means an additional “round trip” is made each time.

    参考来源

    - 位置:《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.6) - 结论依据:原文对比客户端Accept与服务选择的主动协商,以及300候选列表后二次请求的响应式协商。 - 原始内容:An alternative to proactive content negotiation by the service is reactive content negotiation (RCN). In RCN, the service sends the client a list of possible representation formats, and the client is expected to select the preferred format from the list and make the request a second time, specifying which response format has been selected. This puts the power of selection squarely in the hands of the client application but also means an additional “round trip” is made each time.