知识卡片
查询参数过滤并分页
URL 查询参数是问号后的键值对,多个参数用 & 连接。集合端点可用它们过滤、限制或分页结果,例如只取取消订单,或用 page 与 per_page 按页返回。参数与默认值应在接口契约中说明,让列表请求的范围可预期。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Microservice APIs》第 4 章《Principles of REST API design》(源文件:_epub-src/OEBPS/Text/04.htm)
- 结论依据:原文定义查询参数的 URL 形式与过滤用途,随后用 page、per_page 示例说明分页。
- 原始内容:URL query parameters are key-value parameters in the URL. Query parameters come after a question mark (?), and they’re typically used to filter the results of an endpoint, such as the GET /orders endpoint of the orders API. We can combine multiple query parameters by separating them with ampersands (&). ... page represents a set of the data, while per_page tells us how many items we want to include in each set.