Concepts > Pagination

The Trunkery API employs keyset pagination, an efficient method for retrieving a large collection of items page by page. However, this technique does not accommodate arbitrary offsets. To initiate the pagination stream, apply sort_by and sort_desc parameters to a paginated API endpoint. Optionally, you can set the limit parameter to manage the number of items retrieved in a single request. Typically, a paginated API request returns an object with this form (typescript):

interface Page<T> {
  items: T[]; // Items retrieved for this specific request (up to "limit" items).
  last_key: string; // The key used for keyset pagination. Use this key to fetch the next page.

To continue the stream and receive the next page of items, set the last_key parameter to the value from the field with the same name from the most recent page you received.

Library helpers

There are library helpers available for performing pagination:

Unique Identifiers