Skip to main content

Pagination

Cursor Pagination

Cursor Pagination (also known as keyset pagination) is an efficient method for traversing large datasets by using a stable pointer rather than numerical offsets. This approach offers significant performance advantages over traditional offset/limit pagination, particularly when working with large datasets, frequently updated content and ordered results.

In Shoplazza's APIs, when dealing with endpoints that return multiple objects, you'll receive a cursor value acts as a bookmark for your position in the result set, and also indicates how to retrieve the next set of results. The has_more boolean explicitly indicates whether additional results are available.

Here's a simple example:

Assume you are fetching a list of users through an API endpoint. The first API call might return a response like this:

{
"data": [
{
"id": 1,
"name": "Alice"
},
{
"id": 2,
"name": "Bob"
},
...
],
"cursor": "abc123",
"has_more": true
}

To fetch the next set of results, you'd use the cursor value (in this case, "abc123").

If you later navigate to another page and receive a response like:

{
"data": [
{
"id": 101,
"name": "Zack"
},
{
"id": 102,
"name": "Zoe"
},
...
],
"cursor": "def456"
"has_more": true
}

To use these cursors, you typically pass them as query parameters to your API request. For instance:

  • Fetch the first set of results: GET /users
  • Fetch the second set of results: GET /users?cursor=abc123
  • Fetch the third set of results: GET /users?cursor=def456

This is just a conceptual example; the specifics will vary based on the API's implementation. Always refer to the API documentation for exact usage details.