Pagination
Some API endpoints will return paginated results. When results are paginated, the server will return 3 headers related to pagination:
X-Per-Page
: number of results return per pageX-Page
: Id of the current pageX-Total
: total number of results availableLink
: URLs helpers for navigation
Using the Link Header
The Link
header may contain up to 4 different URLs:
rel="first"
: first page of the resultsrel="last"
: last page of the resultsrel="next"
: next page of resultsrel="prev"
: previous page of results
To iterate on results, you simply need to parse the Link
header to find the rel="next"
link. If the link doesn't exist, then it means that there are no more pages to display.
Example
Using JS
Last updated