📋JSON Templates
Pagination Response (Offset-based)
Standard pagination structure for API responses using offset and limit.
Explanation
Offset-based pagination is simple and works well for most use cases.
Examples
Page 1 Response
Output
{
"data": [
{
"id": 1,
"name": "Item 1"
},
{
"id": 2,
"name": "Item 2"
},
{
"id": 3,
"name": "Item 3"
}
],
"pagination": {
"total": 100,
"page": 1,
"pageSize": 3,
"totalPages": 34
}
}Code Examples
TypeScript
interface PaginatedResponse<T> {
data: T[];
pagination: {
total: number;
page: number;
pageSize: number;
totalPages: number;
};
}
// Usage
const response: PaginatedResponse<User> = {
data: users,
pagination: {
total: 100,
page: 1,
pageSize: 20,
totalPages: Math.ceil(100 / 20)
}
};Try it Now
💡 Tips
- Include total count for UI pagination controls
- Set reasonable default and maximum page sizes
- Consider cursor-based pagination for real-time data
- Cache total counts for performance