API Pagination

View Markdown

Overview

Some endpoints return a list of resources. You can use limit and page query parameters to fetch different pages of results.


Limit Param

You can fetch different pages of results by including a limit query parameter in your request.

https://api.ittybit.com/files?limit=5

The default limit is 20.

The minimum limit is 1 and the maximum limit is 100.


Page Param

You can fetch different pages of results by including a page query parameter in your request.

https://api.ittybit.com/files?page=2

The default page is 1.

If you set the page to a number that doesn't exist, you will receive an empty list.


Query Params

You can combine the limit and page query params to fetch different pages of results.

https://api.ittybit.com/files?limit=5&page=2


SDKs

The ittybit SDKs accept pagination parameters in the request options.

const files = await ittybit.files.list({
  limit: 5,
  page: 2
});

In responses which support pagination, the Links header will include URLs for navigating through pages of results. 1

Links:
  <https://api.ittybit.com/files?page=2>; rel="self",
  <https://api.ittybit.com/files?page=1>; rel="first",
  <https://api.ittybit.com/files?page=1>; rel="prev",
  <https://api.ittybit.com/files?page=3>; rel="next",
  <https://api.ittybit.com/files?page=5>; rel="last"

The rel attribute will indicate the relationship of the linked resource to the current resource:

  • self string

    The URL to refetch the current page

  • first string

    The URL to fetch the first page

  • next string | null

    The URL to fetch the next page

  • prev string | null

    The URL to fetch the previous page

  • last string

    The URL to fetch the last page


Footnotes

  1. We have consciously chosen not to include a complete hypermedia implementation. The limited extra functionality is not worth increased response size for every request. Take away our RESTful badge if you want, we don't care. 😊

On this page