octokit.paginate() always returns an array of items even if the raw result was an object.įor example, this script gets all of the issues from the octocat/Spoon-Knife repository. A few endpoints return paginated results as array in an object, as opposed to returning the paginated results as an array. octokit.paginate() will fetch the next page of results until it reaches the last page and then return all of the results as a single array. To fetch paginated results with Octokit.js, you can use octokit.paginate(). Example using the Octokit.js pagination method For more information about Octokit.js, see " Getting started with the REST API" and the Octokit.js README. The following examples use JavaScript and GitHub's Octokit.js library. Instead of manually copying URLs from the link header, you can write a script to fetch multiple pages of results. For example: link: rel="next", rel="last" The per_page parameter will automatically be included in the link header. For more information about query parameters see " Getting started with the REST API."įor example, this request uses the per_page query parameter to return two items per page: curl -include -request GET \ If an endpoint supports the per_page query parameter, then you can control how many results are returned on a page. For more information about query parameters see " Getting started with the REST API." Changing the number of items per page (Some endpoints use the since parameter for something other than pagination.) In all cases, you can use the URLs in the link header to fetch additional pages of results. The query parameters in the link URLs may differ between endpoints: each paginated endpoint will use the page, before/ after, or since query parameters. The URLs in the link header use query parameters to indicate what page of results to return. For example, to request the last page of results based on the previous example: curl -include -request GET \ You can use the URLs from the link header to request another page of results. For example, the link to the previous page won't be included if you are on the first page of results, and the link to the last page won't be included if it can't be calculated. In some cases, only a subset of these links are available. The URL for the first page is followed by rel="first".The URL for the last page is followed by rel="last".The URL for the next page is followed by rel="next".The URL for the previous page is followed by rel="prev".The link header provides the URL for the previous, next, first, and last page of results: If the response is paginated, the link header will look something like this: link: rel="prev", rel="next", rel="last", rel="first" header "Accept: application/vnd.github json" For example: curl -include -request GET \ To see the response headers if you are using a library to make requests, follow the documentation for that library. To see the response headers if you are using curl or GitHub CLI, pass the -include flag with your request. The link header contains URLs that you can used to fetch additional pages of results. The link header will be omitted if the endpoint does not support pagination or if all results fit on a single page. When a response is paginated, the response headers will include a link header. This guide demonstrates how to request additional pages of results for paginated responses, how to change the number of results returned on each page, and how to write a script to fetch multiple pages of results. This makes the response easier to handle for servers and for people. For example, GET /repos/octocat/Spoon-Knife/issues will only return 30 issues from the octocat/Spoon-Knife repository even though the repository includes over 1600 open issues. When a response from the REST API would include many results, GitHub will paginate the results and return a subset of the results.
0 Comments
Leave a Reply. |