知识卡片
嵌套端点避免传整份资源
嵌套端点可以只暴露大资源中的特定细节。例如只想查看订单状态时,请求 /orders/{order_id}/status,无需下载完整订单。这个做法以额外端点换取较小的传输载荷,适用于资源表示较大、客户端常只需要一小部分时。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Microservice APIs》第 4 章《Principles of REST API design》(源文件:_epub-src/OEBPS/Text/04.htm)
- 结论依据:原文用只读取订单状态的嵌套路径说明嵌套端点可避免传输完整大载荷。
- 原始内容:We can create nested endpoints to represent nested resources. Nested endpoints allow us to access specific details of a resource. For example, we can expose a GET /orders/{order_id}/status endpoint that allows us to get an order’s status without all the other details about the order. Using nested endpoints is a common optimization strategy when resources are represented by large payloads since they help us avoid costly data transfers when we are only interested in one property.