By default, the API returns records 50 at a time. If a particular list contains more than 50 records, multiple pages will be returned.
Note
It's possible that the default number of records per page may be changed in the future. Do not assume that 50 records per page are being returned.
It is the responsibility of the process calling the API to determine (by looking at the results), if there are multiple pages of data available and if so, to ensure that all pages are fetched.
The "next" and "previous" fields in the returned data indicate if there are additional pages of data. A value of null indicates there is no next or previous page of data.
Note
The examples in this section are using the base URL https://ap.ua.painchek.com/api/assessments/, but the information here applies to any list of objects returned by the API.
If a list returns a single page of data, the return looks like this:
{ "count": 0, "next": null, "previous": null, "results": [] }
In the above example, not only is there no other pages of data (next and previous are both null), there is, in fact, no data at all (the count is 0 and the results array is empty).
If a request such as this:
curl https://ap.ua.painchek.com/api/assessments/
...is returning multiple pages (i.e. more than 50 records in total), the response to that initial request will look like this:
{ "count": 102, "next": "https://ap.ua.painchek.com/api/assessments/?page=2", "previous": null, "results": [{ "item": "record 1" }, { "item": "record 2" }, ..., { "item": "record 50" }] }
What is returned in this case in the results array is the first 50 records. Note that the count is the total records (102) that are in the list, rather than just the count of records included in the returned page.
The "next" record shows the URL of the next page of data (page 2). As this is the first page, there is no "previous" page.
As the first call returned a "next" value of "https://ap.ua.painchek.com/api/assessments/?page=2", we know to make this call to fetch the next page of records:
curl https: //ap.ua.painchek.com/api/assessments/?page=2
That would return something like this:
{ "count": 102, "next": "https://ap.ua.painchek.com/api/assessments/?page=3", "previous": https: //ap.ua.painchek.com/api/assessments/?page=1,"results": [{"item":"record 51"},{"item":"record 52"},...,{"item":"record 100"}] }
What is returned in this case in the results array is the next 50 records (i.e. records 21 to 40).
The "next" record shows the URL of the next page of data (page 3) and the "previous" record shows the URL of the previous page of data (page 1).
As the second call returned a next value of "https://ap.ua.painchek.com/api/assessments/?page=3", we know to make this call to fetch the next page of records:
curl https: //ap.ua.painchek.com/api/assessments/?page=3
That would return something like this:
{ "count": 102, "next": null, "previous": https: //ap.ua.painchek.com/api/assessments/?page=2,"results": [{"item":"record 101"},{"item":"record 102"}] }
What is returned in this case is the last 2 records - records 101 and 102.
The "previous" record shows the URL of the next page of data (page 2). As this is the last page, there is no "next" page and that lets the calling process know that there is no more data to fetch.
The default number of records per page is 50. You can change that by passing the page_size parameter.e.g.:
curl https: //ap.ua.painchek.com/api/assessments/?page_size=10
That would return something like this:
{ "count": 102, "next": https: //ap.ua.painchek.com/api/assessments/?page=2&page_size=10,"previous": null,"results": [{"item":"record 1"},{"item":"record 2"},...,{"item":"record 10"}] }
What is returned in this case in the results array is the first 10 records.
Note that the "next" record also includes the page_size parameter in the URL.