Appearance
Pagination
Canteen's Admin API supports page-based pagination for endpoints that return lists of data. This ensures efficient data retrieval and prevents performance issues when handling large datasets.
Requesting Paginated Data
To paginate results, use the following query parameters:
Parameter | Type | Description |
---|---|---|
page | integer | The page number to retrieve (default: 1 ). |
per_page | integer | The number of items per page (default: 25 , max: 100 ). |
Example Request:
bash
curl -X GET "https://your-org-uuid.canteenweb.com/api/v1/admin/orders?page=2&per_page=25" \
-H "Authorization: Bearer your-access-token"
Pagination Response Structure
Paginated responses include metadata to help navigate through the dataset:
json
{
"success": true,
"message": "Orders retrieved successfully.",
"data": [
{
"id": 1,
"amount": 500,
"status": "completed",
"created_at": "2024-02-12T10:00:00Z"
}
],
"meta": {
"current_page": 2,
"last_page": 5,
"per_page": 25,
"total": 120
},
"links": {
"first": "https://your-org-uuid.canteenweb.com/api/v1/admin/orders?page=1",
"last": "https://your-org-uuid.canteenweb.com/api/v1/admin/orders?page=5",
"prev": "https://your-org-uuid.canteenweb.com/api/v1/admin/orders?page=1",
"next": "https://your-org-uuid.canteenweb.com/api/v1/admin/orders?page=3"
}
}
Pagination Metadata
Field | Type | Description |
---|---|---|
current_page | integer | The current page number. |
last_page | integer | The total number of pages available. |
per_page | integer | The number of items returned per page. |
total | integer | The total number of records available. |
Pagination Links
Field | Description |
---|---|
first | URL of the first page. |
last | URL of the last page. |
prev | URL of the previous page (null if on the first page). |
next | URL of the next page (null if on the last page). |
Handling Pagination in Code
To navigate through paginated results, use the links
section in the response.
Example in JavaScript:
js
async function fetchorders(page = 1) {
const response = await fetch(`https://your-org-uuid.canteenweb.com/api/v1/admin/orders?page=${page}`, {
headers: { 'Authorization': 'Bearer your-access-token' }
});
const data = await response.json();
console.log('orders:', data.data);
if (data.links.next) {
console.log('Next Page URL:', data.links.next);
}
}
Best Practices
- Always check the
last_page
value to prevent unnecessary requests. - Use
per_page
wisely to balance performance and data retrieval needs. - Handle the
links.next
value dynamically to fetch additional pages as needed.