Pagination Methods
There are two primary ways to paginate results:- Limit/Offset: Specify the number of items and how many to skip
- Limit/Page: Specify the number of items per page and the page number
Limit Parameter
Thelimit parameter controls how many results to return:
Aliases
Thelimit parameter has an alias:
limitper_page
Examples
Without a
limit parameter, the API may return all results or use a server-configured default limit.Offset-Based Pagination
Offset-based pagination useslimit and offset parameters:
- limit: Number of items to return
- offset: Number of items to skip
Syntax
Examples
Calculation
To calculate the offset for a specific page:Use Cases
- When you need precise control over which items to retrieve
- When implementing custom pagination logic
- When you want to skip to specific positions in the dataset
Page-Based Pagination
Page-based pagination useslimit and page parameters:
- limit: Number of items per page
- page: Page number (1-indexed)
Syntax
Examples
Use Cases
- When building traditional paginated UIs with page numbers
- When implementing “Previous” and “Next” navigation
- When the user needs to jump to a specific page
Offset vs Page
Cannot Use Both
Pagination with Sorting
Always use the same sort order across paginated requests:Best Practice
Pagination with Filtering
Combine pagination with filters to paginate through filtered results:Important Considerations
- Keep filters consistent: Use the same filters across all pages
- Total count may change: If data is added/removed, total pages may change
- Filter before paginating: Pagination applies to filtered results
Complete Pagination Examples
Basic Pagination
With Sorting
With Filtering and Sorting
With Field Selection
Implementing Pagination in Frontend
React Example
JavaScript with RequestQueryBuilder
Infinite Scroll
For infinite scroll UIs, use offset-based pagination:Cursor-Based Pagination
For datasets that frequently change, consider cursor-based pagination using filters:Performance Considerations
Always Use Limits
Avoid Large Offsets
Index Sorted Fields
Always create database indexes on fields used for sorting in pagination:Common Pagination Patterns
Standard Table Pagination
Mobile Feed
Search Results
Error Handling
Invalid pagination parameters will throw aRequestQueryException:
Best Practices
- Always set a limit: Never rely on default limits
- Use consistent sorting: Keep the same sort order across pages
- Choose the right method: Use
pagefor UI,offsetfor precise control - Consider cursor pagination: For frequently changing datasets
- Index sorted fields: Add database indexes to improve performance
- Document limits: Let API consumers know the maximum allowed limit
- Return metadata: Include total count, total pages, current page in responses
- Handle edge cases: Validate page numbers and offsets
Response Metadata
Consider including pagination metadata in your API responses:Next Steps
Sorting
Learn how to sort paginated results
Filtering
Combine pagination with filters
Relations
Paginate results with joined relations
Query Parameters
Overview of all query parameters