Pagination API Reference

This document details the pagination strategies employed by our API to manage large datasets efficiently. Proper pagination ensures that you can retrieve data in manageable chunks, reducing load times and improving the overall performance of your application.

Overview

Our API uses a cursor-based pagination system. This means that instead of using page numbers, you'll use cursors (unique identifiers) to fetch subsequent or previous sets of results. This approach is more robust for frequently updated datasets as it's not affected by items being added or removed between page requests.

Response Structure

Each paginated response will include the following fields:

Example Response

{
    "data": [
        { "id": 1, "name": "Item Alpha" },
        { "id": 2, "name": "Item Beta" },
        { "id": 3, "name": "Item Gamma" }
    ],
    "links": {
        "next": "/api/v1/items?cursor=next_cursor_id_abc123",
        "prev": "/api/v1/items?cursor=prev_cursor_id_xyz789"
    },
    "meta": {
        "totalItems": 150,
        "itemsPerPage": 10,
        "currentPage": 1
    }
}

Requesting Paginated Data

To request a specific page of results, you will append a cursor query parameter to the relevant endpoint. The value of this cursor is provided in the links.next or links.prev field of the previous response.

Fetching the First Page

To get the initial set of results, simply make a request to the endpoint without any cursor parameters.

Request:

GET /api/v1/items

Fetching Subsequent Pages

To fetch the next page, use the next URL provided in the links object of the previous response.

Request (using next link from previous response):

GET /api/v1/items?cursor=next_cursor_id_abc123

Fetching Previous Pages

To fetch the previous page, use the prev URL provided in the links object of the previous response.

Request (using prev link from previous response):

GET /api/v1/items?cursor=prev_cursor_id_xyz789

Parameters

The primary parameter used for pagination is:

Parameter Type Description Required
cursor String A unique identifier representing the starting point for fetching results. Obtained from the links.next or links.prev fields of a previous response. No (for the first page)

Metadata

The meta object in the response provides valuable context about the paginated data.

Field Type Description
totalItems Integer The total number of items available across all pages.
itemsPerPage Integer The number of items returned in the current batch.
currentPage Integer The current page number (for informational purposes).
hasNextPage Boolean Indicates if there are more pages available after the current one.
hasPrevPage Boolean Indicates if there are previous pages available before the current one.
Note: When links.next is not present in the response, it signifies that you have reached the end of the dataset. Similarly, if links.prev is absent, you are at the beginning.