此卡片不在当前主题的阅读序列中,可返回主题继续阅读。
知识卡片
查询语言封装为媒体类型
接口需要强查询能力,却又不能随查询引擎更换而整体改写时,可以隔开语言消息与实际存储。
需要SQL、GraphQL等强查询能力时,把查询当作带媒体类型的请求消息,由接口负责转换到实际引擎,而非把接口直接等同于某引擎。Content-Type说明查询语言,Accept说明结果表示,二者可以独立。
例如书中以Content-Type: application/sql提交查询并创建查询资源;查询与结果是两个不同资源。支持更多语言仍需编写转换器并承担语义兼容成本。书中application/prs.*是其2022年示例中的自定义标识,不构成现行注册状态承诺。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 分布式数据 · 查看原书依据
Communicating data queries via a media type encapsulates the data technology to a strongly typed message format. It also makes it possible to implement multiple data query languages for the same data store without making changes to the interface. That means you can implement support for application/sql when you first release the API and, if needed, you can also safely add support for Solr or GraphQL at some future date.