What are the pagination strategies in REST APIs?

Answer

Three main pagination strategies are used in REST. Page/offset pagination: GET /posts?page=3&limit=20 — simple to implement and understand but unstable with live data (inserting an item shifts all subsequent pages). Offset/limit pagination: GET /posts?offset=40&limit=20 — similar to page/limit but more flexible. Cursor-based (keyset) pagination: GET /posts?after=cursor123&limit=20 — the cursor is typically an encoded last-seen ID or timestamp. It is stable (insertions/deletions do not affect other pages) and performs better on large datasets (no OFFSET in SQL). The response should include pagination metadata: { "data": [...], "meta": { "total": 500, "next": "/posts?after=xyz", "hasMore": true } }. Cursor-based is preferred for large, frequently-changing datasets like social media feeds.