What this prompt does
This prompt makes the AI an API design expert implementing pagination for a [framework] API serving data from [database] with tables up to [row_count] rows. It implements offset-based pagination, cursor-based pagination, a keyset variant, a decision matrix, nested-resource pagination, and integration tests. Offset pagination uses [default_page_size]/[max_page_size] limits, while cursor pagination encodes a [cursor_encoding] cursor and uses WHERE clauses instead of OFFSET.
The structure works because pagination is a quiet performance killer when you default to OFFSET everywhere. On large tables, OFFSET still scans and discards every skipped row, so requesting a deep page on a [row_count]-row table gets progressively slower; the prompt deliberately offers cursor and keyset strategies that seek directly to the cursor position instead. The keyset variant encodes all the sort-field values for [sort_fields] so pagination stays stable even as rows are inserted or deleted between requests, avoiding the skipped and duplicated rows that plague offset paging on live data. The decision matrix then maps each of your [endpoint_count] endpoints to the right strategy based on whether it needs total counts, stable sort keys, large-dataset performance, or random page access.
When to use it
- You're choosing pagination per endpoint instead of defaulting to OFFSET everywhere
- A large table's listing query degrades as users page deeper
- You need stable pagination over feeds that change between requests
- You want a decision matrix to justify cursor versus offset for each endpoint
- You're paginating nested resources independently of their parent
- You want edge cases like deletes and concurrent inserts covered by tests
- You need both a count-bearing offset envelope and a high-volume cursor option in one API
Example output
Expect implementation plus guidance: reusable offset middleware with [default_page_size]/[max_page_size] limits, a response envelope, and first/prev/next/last navigation links, cursor-based logic encoding [cursor_encoding] cursors with next_cursor, prev_cursor, and has_more, a keyset variant for compound sorts over [sort_fields], a decision matrix table mapping [endpoint_count] endpoints to strategies with tradeoffs, nested-resource pagination for endpoints like /users/:id/[nested_resource], and integration tests with benchmarks at [row_count] rows including query execution plans. It's structured as labeled [framework] steps.
Pro tips
- Don't reach for offset on big tables — deep OFFSET scans and discards every skipped row, which is the slow path the prompt steers you off
- Use cursor or keyset pagination for feeds and high-volume endpoints where stability matters more than random page access
- Encode all sort-key values in the cursor for
[sort_fields]so results stay stable when rows are inserted or deleted mid-paging - Reserve offset for small, bounded datasets where users genuinely need to jump to an arbitrary page
- Be honest in the decision matrix: if an endpoint truly needs a total count, that's a real cost cursor pagination doesn't give cheaply
- Test deletes and concurrent inserts between pages; that's where naive pagination quietly skips or duplicates rows