5.6. 使用带有 Pagination Control 的搜索
您可以使用 per_page
和 page
pagination 参数来限制 API 搜索查询返回的搜索结果。per_
参数指定每个页面的结果数,而 page 参数指定按 per_page 参数计算的页面(按 page
per_page
参数计算)。
当您没有指定任何 pagination 参数时,返回的默认项目数量被设置为 1000,但每个 页
值的默认值是 20,用于指定 page
参数时适用。
列出内容视图
本例返回页面中的 Content Views 列表。该列表每行包含 10 个键,并返回第三个页面。
请求示例:
curl --request GET --user sat_username:sat_password \ https://satellite.example.com/katello/api/content_views?per_page=10&page=3
$ curl --request GET --user sat_username:sat_password \
https://satellite.example.com/katello/api/content_views?per_page=10&page=3
列出激活码
这个示例会返回一个机构在页面中 ID 为 1
的激活码列表。该列表每行包含 30 密钥,并返回第二个页面。
请求示例:
curl --request GET --user sat_username:sat_password \ https://satellite.example.com/katello/api/activation_keys?organization_id=1&per_page=30&page=2
$ curl --request GET --user sat_username:sat_password \
https://satellite.example.com/katello/api/activation_keys?organization_id=1&per_page=30&page=2
返回多个页面
您可以使用 for
循环结构来获取多个结果页面。
这个示例将页面 1 返回到 Content Views,每个页面有 5 个结果:
for i in seq 1 3; do \ curl --request GET --user sat_username:sat_password \ https://satellite.example.com/katello/api/content_views?per_page=5&page=$i; \ done
$ for i in seq 1 3; do \
curl --request GET --user sat_username:sat_password \
https://satellite.example.com/katello/api/content_views?per_page=5&page=$i; \
done