Pagination

In this guide, we will look at how to work with paginated responses when querying the Caruuto API. By default, all responses limit results to ten. However, you can go as high as 100 by adding a limit parameter to your requests.

When an API response returns a list of objects, no matter the amount, pagination is supported. In paginated responses, objects are contained in a results array and alongside that is returned a metadata object. The metadata object will have a nextPage attribute that indicates whether you have reached the end of the last page. You can use the page query parameters to browse pages.

Example

In this example, we request the second page of 10 results. We can tell by the lack of a nextPage attribute that we have reached the end of the resultset.

  • Name
    page
    Type
    integer
    Description

    The number of the page you want to fetch.

  • Name
    limit
    Type
    integer
    Description

    Limit the number of items returned.

Manual pagination using cURL

curl -G https://caruuto.com/api/v1/posts \
  -H "Authorization: Api-Key-v1 {apiKey}" \
  -d page=2 \
  -d limit=10

Paginated response

{
  "results": [
    {
      "id": "WAz8eIbvDR60rouK",
      // ...
    }
  ],
  "metadata": {
    "page":2,
    "limit":10,
    "fields":[],
    "offset":10,
    "totalCount":11,
    "totalPages":2,
    "prevPage":1,
    "pageStart":11,
    "pageEnd":11,
    "prevPageUrl":"https://caruuto.com/api/v1/posts?page=1"
  }
}

Was this page helpful?