返回主题:引擎运行时与状态管理

此卡片不在当前主题的阅读序列中,可返回主题继续阅读。

知识卡片

问题卡 · 2499.b

查询语言封装为媒体类型

理解等级:中级

接口需要强查询能力,却又不能随查询引擎更换而整体改写时,可以隔开语言消息与实际存储。

需要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.

    参考来源

    - 位置:《RESTful Web API Patterns and Practices Cookbook Connecting and Orchestrating Microservices and Distributed Data (Mike Amundsen)》第6章《分布式数据》§6.7(来源项目:book-sources;源文件:extracted/RESTful Web API Patterns and Practices Cookbook Connecting and Orchestrating Microservices and Distributed Data (Mike Amundsen)/_epub-src/OEBPS/ch06.xhtml) - 结论依据:原文以需要SQL、GraphQL等强查询能力时,把查询当作带媒体类型的请求消息,由接口负责转换到实际引擎,而非把接口直接等同于某引擎的方式说明该用途;同节示例与讨论补充了卡内条件和边界。 - 原始内容: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.