To view this content in our official product documentation, click here.
Overview
This method is similar to the link header approach, except that the URL for the next page is included in the response body, rather than the header.
Next page URL options
| Option | Summary |
|---|---|
| Next page field | Enter the location of the next page URL within the payload. |
Example
Suppose we set the following options:
| Option | Value |
|---|---|
| Next page field | links.next |
...and we send a request to get the first page of data:
{% code lineNumbers="true" %}
GET https://my.shop/api/customers?page=1The response will include the first page of data, together with a URL that should be used to get the next page of results. For example:
{% code lineNumbers="true" %}
{
"data": [
{"id": 1, "name": "Alice"},
{"id": 2, "name": "Bob"},
{"id": 3, "name": "Charlie"},
{"id": 4, "name": "Lyn"},
{"id": 5, "name": "John"},
{"id": 6, "name": "Gordon"},
{"id": 7, "name": "Izzy"},
{"id": 8, "name": "Mike"},
{"id": 9, "name": "Ralph"},
{"id": 10, "name": "Rex"}
],
"links": {
"next": "https://my.shop/api/customers?page=2"
}
}Notice the links.next section at the end of this response, which includes our next page URL. So, our request for the next page of results would be:
{% code lineNumbers="true" %}
https://my.shop/api/customers?page=2Relative URLs
When a request is sent for data using the next page URL pagination type, the response will include the first page of data, together with a URL that should be used to get the next page of results (i.e. the next page URL). For example:
https://api.example.com/products?page=2
This URL is included in subsequent pages, until the last page. However, some APIs don't return the full URL in pagination responses - instead, they just return query parameters. For example:
?page=2
Patchworks recognises this as a relative URL, based on the ? character at the start. When a relative URL is returned, the base URL from the previous request is appended to the start. So in our example, ?page=2 would be interpreted as https://api.example.com/products?page=2.
When does pagination stop?
Pagination continues until the next page URL is no longer included in the payload.
Comments
0 comments
Please sign in to leave a comment.