Offset-Based Pagination
What you'll learn: How to use limit and offset parameters to retrieve specific pages of results from an API.
The Core Idea
Offset-based pagination works like skipping to a specific page in a book. Instead of loading all results at once, you tell the API how many items to skip (the offset) and how many to return (the limit). This allows you to request data in manageable chunks.
How It Works
The API accepts two query parameters:
limit: How many items to return (e.g., 10, 20, 50)offset: How many items to skip before starting (e.g., 0, 20, 40)
For example, to fetch the first page of users with 10 items per page:
GET /api/users?limit=10&offset=0
For the second page, skip the first 10 results:
GET /api/users?limit=10&offset=10
For the third page:
GET /api/users?limit=10&offset=20
The Math Behind It
Calculate offset from page number:
offset = (pageNumber - 1) × limit
So page 3 with a limit of 10 means: offset = (3 - 1) × 10 = 20
Real-World Analogy
Think of a library with 1,000 books. Instead of carrying all 1,000 at once, you ask the librarian: "Give me 10 books, starting from book #21" (limit=10, offset=20). Next trip: "Give me 10 more, starting from book #31" (limit=10, offset=30).
Common Pattern
Most paginated responses include metadata to help you navigate:
{
"data": [...],
"total": 150,
"limit": 10,
"offset": 20
}
Key Takeaway: Offset-based pagination uses limit to control page size and offset to skip past previous pages, making it easy to fetch data in numbered chunks.