← 返回刚才阅读的位置

知识卡片

问题卡 · 1968.t.1.a

显式映射外部表示

理解等级:中级

同一内部模型要向不同消费者提供多种格式时,直接序列化会把内部变化传播到接口。

返回消息要单独设计,不能直接序列化内部对象。服务先解析Accept选择格式,再按该媒体类型规则映射内部数据;同一电话对象可在CSV中摊平为两列,在超媒体中变成关联资源。

映射规则应供内部开发维护,却不必把内部结构公开给消费者。新增CSV字段宜追加,重排既有列可能破坏客户端;Collection+JSON的name/value结构更能容纳属性变化。多格式支持可组合高超媒体能力格式、简单序列化和便于人工试用的HTML。

关联:[[外部模型独立设计]]。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

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

      An important way to make sure your service interface design is not too tightly coupled to your service’s internal data (or object) model, is to approach the representation step as a separate design effort. In other words, actively engage in the process of designing your representations—don’t just settle for a simple, direct serialization of internal models into external messages.

    参考来源

    - 位置:《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.3) - 结论依据:原文把JSON、CSV及Collection+JSON视图与内部电话数据对照,并讨论映射规则和列顺序兼容。 - 原始内容:An important way to make sure your service interface design is not too tightly coupled to your service’s internal data (or object) model, is to approach the representation step as a separate design effort. In other words, actively engage in the process of designing your representations—don’t just settle for a simple, direct serialization of internal models into external messages.