Cursor Pagination

"Cursor" pagination, also known as "keyset" pagination, is a method where you use a pointer (the cursor) to navigate through your results rather than the more traditional "offset/limit" method. The primary advantage of cursor-based pagination is its ability to efficiently paginate through large datasets without the performance pitfalls that can come with offset-based approaches.

In many APIs in Shoplazza, you'll receive a "cursor" value indicating how to retrieve the next set of results. The inclusion of a "pre_cursor" suggests the ability to navigate back to previous sets of results as well.

Here's a simple example:

Let's assume you have an API endpoint for fetching a list of users. The first time you hit the endpoint, the response might look something like this:

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

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",
  "pre_cursor": "abc123"
}

You can use the cursor value ("abc123") to go back and fetch the previous set of results.

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

  • To get the first set: GET /users
  • To get the second set: GET /users?cursor=abc123
  • To get the third set: GET /users?cursor=def456
  • To get the previous set while you are on the second set: GET /users?pre_cursor=abc123 (The exact implementation may vary depending on the API.)

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.