知识卡片

普通读书笔记卡 · 3436.c

集合响应权衡完整与精简

理解等级:高级

集合端点可返回每项的完整表示,让客户端一次取齐;也可只返回 ID 或必要字段,缩小载荷,但客户端可能需要逐项再请求详情。选择时要看列表项大小、客户端实际展示需求与额外请求成本,不能只追求最短响应。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    原书出处

    参考来源

    - 位置:《Microservice APIs》第 4 章《Principles of REST API design》(源文件:_epub-src/OEBPS/Text/04.htm) - 结论依据:原文对比 GET /orders 的完整与部分列表表示,指出完整载荷较大,部分表示需后续按 ID 请求详情。 - 原始内容:To design the contents of the list, we have two strategies: include a full representation of each order or include a partial representation of each order. ... the first strategy gives the API client all the information they need in one request. However, this strategy may compromise the performance of the API when the items in the list are big, resulting in a large response payload. ... the client must call the GET /orders/{order_id} endpoint to get a full representation of each order.