From 8026d420c9a0ffa3f6393c38487d12b3315efa73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Thu, 14 Jan 2016 17:14:20 +0100 Subject: Document new API pagination headers --- doc/api/README.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'doc/api') diff --git a/doc/api/README.md b/doc/api/README.md index c3401bcbc9d..953138cb374 100644 --- a/doc/api/README.md +++ b/doc/api/README.md @@ -149,7 +149,30 @@ When listing resources you can pass the following parameters: - `page` (default: `1`) - page number - `per_page` (default: `20`, max: `100`) - number of items to list per page -[Link headers](http://www.w3.org/wiki/LinkHeader) are send back with each response. These have `rel` prev/next/first/last and contain the relevant URL. Please use these instead of generating your own URLs. +### `Link` header + +[Link headers](http://www.w3.org/wiki/LinkHeader) are sent back with each response. These have `rel` prev/next/first/last and contain the relevant URL. Please use these instead of generating your own URLs. + +Example of `Link` header (line breaks added for clarity): +``` +$ curl -I -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" \ +https://gitlab.example.com/api/v3/projects/gitlab-org/gitlab-ce/issues/1/notes?per_page=1&page=2 + +Link: ; rel="prev", +; rel="next", +; rel="first", +; rel="last" +``` + +### Other pagination headers + +Additional pagination headers are also sent back: +- `X-Total`: number of items returned in this page +- `X-Total-Pages`: total number of pages of items +- `X-Per-Page`: number of items per page +- `X-Page`: index of the current page (starting at 1) +- `X-Next-Page`: index of the next page +- `X-Prev-Page`: index of the previous page ## id vs iid -- cgit v1.2.3 From 4a76f9217a7aba54ac5e57f12d9d8b448f225557 Mon Sep 17 00:00:00 2001 From: Achilleas Pipinellis Date: Mon, 18 Jan 2016 10:55:25 +0100 Subject: Clean up pagination documentation [ci skip] - Fix heading names - Fix curl example - Use full request output - Use table for the extra headers --- doc/api/README.md | 55 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 16 deletions(-) (limited to 'doc/api') diff --git a/doc/api/README.md b/doc/api/README.md index 953138cb374..64169885cd4 100644 --- a/doc/api/README.md +++ b/doc/api/README.md @@ -149,30 +149,53 @@ When listing resources you can pass the following parameters: - `page` (default: `1`) - page number - `per_page` (default: `20`, max: `100`) - number of items to list per page -### `Link` header +### Pagination Link header -[Link headers](http://www.w3.org/wiki/LinkHeader) are sent back with each response. These have `rel` prev/next/first/last and contain the relevant URL. Please use these instead of generating your own URLs. +[Link headers](http://www.w3.org/wiki/LinkHeader) are sent back with each +response. They have `rel` set to prev/next/first/last and contain the relevant +URL. Please use these links instead of generating your own URLs. -Example of `Link` header (line breaks added for clarity): +In the cURL example below, we limit the output to 3 items per page (`per_page=3`) +and we request the second page (`page=2`) of [comments](notes.md) of the issue +with ID `8` which belongs to the project with ID `8`: + +```bash +curl -I -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/projects/8/issues/8/notes?per_page=3&page=2 ``` -$ curl -I -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" \ -https://gitlab.example.com/api/v3/projects/gitlab-org/gitlab-ce/issues/1/notes?per_page=1&page=2 -Link: ; rel="prev", -; rel="next", -; rel="first", -; rel="last" +The response will then be: + +``` +HTTP/1.1 200 OK +Cache-Control: no-cache +Content-Length: 1103 +Content-Type: application/json +Date: Mon, 18 Jan 2016 09:43:18 GMT +Link: ; rel="prev", ; rel="next", ; rel="first", ; rel="last" +Status: 200 OK +Vary: Origin +X-Next-Page: 3 +X-Page: 2 +X-Per-Page: 3 +X-Prev-Page: 1 +X-Request-Id: 732ad4ee-9870-4866-a199-a9db0cde3c86 +X-Runtime: 0.108688 +X-Total: 8 +X-Total-Pages: 3 ``` ### Other pagination headers -Additional pagination headers are also sent back: -- `X-Total`: number of items returned in this page -- `X-Total-Pages`: total number of pages of items -- `X-Per-Page`: number of items per page -- `X-Page`: index of the current page (starting at 1) -- `X-Next-Page`: index of the next page -- `X-Prev-Page`: index of the previous page +Additional pagination headers are also sent back. + +| Header | Description | +| ------ | ----------- | +| `X-Total` | The total number of items | +| `X-Total-Pages` | The total number of pages | +| `X-Per-Page` | The number of items per page | +| `X-Page` | The index of the current page (starting at 1) | +| `X-Next-Page` | The index of the next page | +| `X-Prev-Page` | The index of the previous page | ## id vs iid -- cgit v1.2.3