Offset
Introduction
Offset pagination is a simple pagination strategy that uses the limit
parameter to select a specific number of results and the offset
parameter to skip a certain number of results.
👍 Pros of Offset Pagination
- Random access: You can jump to any desired position by specifying the
offset
value. For example, you can fetch the 10001st row by settingoffset=10000
andlimit=1
.
👎 Cons of Offset Pagination
- Performance impact: The database or warehouse needs to iterate through the skipped rows before retrieving the data. For instance, if you skip 10000 rows and fetch 1 row, it has to traverse all the 10000 rows before providing the result.
Configuration
Set pagination.mode
to offset
to enable this pagination strategy.
customers.yaml
urlPath: /customers
pagination:
mode: offset
profiles:
- pg
Usage
The offset pagination requires two parameters: offset
and limit
.
- To fetch the first 10 rows: /api/customers?limit=10
- To fetch rows 11 to 20: /api/customers?limit=10&offset=10