知识卡片
集合响应预留分页结构
集合端点若直接返回裸数组,后来要增加下一页链接、总量或其他元数据时,可能不得不改变响应顶层类型。早期用对象包住集合,可为分页扩展留位置;这不是所有小集合都必须分页,而是先评估未来增长与兼容成本。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- · 查看原书依据
It may seem strange that an array response is returned in an object, however the reason for this is that it allows for us to model bigger collections and pagination. Pagination involves returning a partial result, while providing instructions for how the consumer can request the next set of results.
参考来源
- 位置:《Mastering API Architecture》第1章《Design, Build, and Specify APIs》之《Collections and Pagination》(源文件:_epub-src/OEBPS/ch01.xhtml)
- 结论依据:原文比较裸数组与对象包裹的集合响应,并指出后加分页链接时从数组改为对象会破坏现有消费者。
- 原始内容:It may seem strange that an array response is returned in an object, however the reason for this is that it allows for us to model bigger collections and pagination. Pagination involves returning a partial result, while providing instructions for how the consumer can request the next set of results.