← 返回刚才阅读的位置

知识卡片

问题卡 · 618.d.1.e

发布可缓存偏好资源

理解等级:中级

消费者不知道服务支持哪些请求和响应选项时,需要可发现且负担可控的能力说明。

服务可把支持的方法、响应格式、请求编码、字符集、压缩、语言和profile列入元数据,供客户端在运行时决定请求偏好。即使某项只有一个值也列出,以免客户端猜测。

书中建议同时用OPTIONS与rel="meta"独立资源公布,并在头与正文表达适用信息。OPTIONS响应不可缓存;示例出现缓存头也不能改变这一点。独立GET偏好资源可以设置缓存寿命,减少大量消费者重复获取能力文档的负担。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

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

      There is a downside to relying solely on HTTP OPTIONS to communicate supported client preferences. The HTTP specification explicitly states that OPTIONS is noncacheable. If you have lots of API consumers sending OPTIONS requests, you may run into scaling problems for your API. However, offering a standalone meta-preferences resource (for example, <link rel="meta" href="http://api.example.org/meta-preferences/" />) means you can mark that resource with a long cache lifetime and reduce the expense of composing and returning client preference responses.

    参考来源

    - 位置:《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.5) - 结论依据:原文明确OPTIONS不可缓存,并以独立meta-preferences资源解释缓存能力文档的成本优势。 - 原始内容:There is a downside to relying solely on HTTP OPTIONS to communicate supported client preferences. The HTTP specification explicitly states that OPTIONS is noncacheable. If you have lots of API consumers sending OPTIONS requests, you may run into scaling problems for your API. However, offering a standalone meta-preferences resource (for example, <link rel="meta" href="http://api.example.org/meta-preferences/" />) means you can mark that resource with a long cache lifetime and reduce the expense of composing and returning client preference responses.