Pagination

Pagination

We understand that handling a large amount of information can be challenging. That's why we've implemented a straightforward pagination system using the concepts of "limit" and "offset."

Understanding pagination

Pagination is a method that divides a vast dataset into smaller, more manageable portions (the "pages"). Instead of receiving all the data at once, you can request a specific number of items ("limit") starting from a particular position ("offset"). This approach is particularly useful when dealing with extensive data, as it enhances usability and performance.

How to use pagination

To retrieve a specific page of data, you need to include two parameters in your API request:

  • limit: This parameter specifies the maximum number of items you want to receive on a single page.
  • offset: This parameter indicates the starting point within the result set.

Example:

GET https://api.safsira.com/v1/products?limit=24&offset=24

First, when accessing a paginated endpoint the response will be something like this:

{
    "count": 24,
    "next": "https://api.safsira.com/v1/products?limit=24&offset=48",
    "previous": "https://api.safsira.com/v1/products?limit=24&offset=0",
    "results": [
        // Array of up to 24 product objects
    ]
}

By incrementing the offset value, you can retrieve subsequent chunks of data. For example, to get the next page of results, you would use the following request:

GET https://api.safsira.com/v1/products?limit=24&offset=48