Pagination
When you request data from our API, such as a list of draws, the number of results can be very large. Returning all the data at once could be slow, heavy, and difficult to handle for both users and servers. Pagination is a way to split the results into smaller, manageable chunks so you can fetch them page by page efficiently.
Pagination allows you to:
- Reduce the load on the server and your application
- Avoid downloading unnecessary data
- Navigate through large datasets easily
In our API, pagination is controlled using four main options: limit, offset, more, and total.
Info
Pagination is only available when a list of resources is returned by the API.
Options
1. Limit
The limit parameter specifies the maximum number of items returned in a single API call. It helps you avoid receiving too much data at once and lets you choose the "page size" for your requests.
Note: limit is subject to a maximum value to avoid breaking applications.
Info
The maximum limits may change in future versions. Currently, the maximum value is 15 entries per page.
2. Offset
The offset parameter tells the API to skip a certain number of results before starting to return items. It is useful to get the "next page" of data and works together with limit to paginate through results.
3. More
The more parameter is a boolean value in the response indicating whether additional results are available after the current page.
true→ there are more resultsfalse→ this is the last page
You can rely on the more value to control loops if you want to fetch all resources.
4. Total
The total parameter is an informative value that indicates the total number of entries in the dataset.
- It is primarily for informational purposes and does not affect pagination logic.
- If you want to retrieve the total number of entries without fetching the resources themselves, you can make the following request:
This request will return the total number of entries without returning any resource data.
Example : Fetching lottery draws page by page
Suppose you want to fetch all lottery draws in batches of 5. You could do the following:
1. First request:
curl -H 'X-API-Token: MY_SECRET_TOKEN' \
https://api.lotteryresultsapi.com/lottery/fr_lotto/draws?limit=5
2. Check the more flag:
If "more": true, increase offset by limit (here: 5)
3. Next request:
curl -H 'X-API-Token: MY_SECRET_TOKEN' \
https://api.lotteryresultsapi.com/lottery/fr_lotto/draws?limit=5&offset=5
4. Repeat until "more": false
This way, you efficiently retrieve all lottery draws.