知识卡片
发布可缓存偏好资源
消费者不知道服务支持哪些请求和响应选项时,需要可发现且负担可控的能力说明。
服务可把支持的方法、响应格式、请求编码、字符集、压缩、语言和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.