Pagination and Filtering API Design
Choose cursor or offset pagination and design filters.
The Open buttons send the prompt text as currently shown below to that site only when you click. Fill in the placeholders first.
Design pagination, filtering, and sorting for my API. Resource and size: [RESOURCE_AND_SIZE]. Typical access patterns: [ACCESS_PATTERNS]. Database: [DATABASE]. Consumers: [CONSUMERS]. Data changes while clients page through it: [CHANGE_FREQUENCY]. Use this tree: 1. Does the client need random access to page N? If yes, offset pagination with limit and offset; explain the cost on large tables and drift when rows are inserted. If no, go to 2. 2. Does the list change frequently or is it large? Prefer cursor (keyset) pagination using a stable, unique sort key; show how the cursor is encoded and validated, and what happens with a tie on the sort field. 3. Do clients need a total count? Explain the cost and offer an optional approximate count. 4. Filtering: design query parameter syntax for equality, ranges, in-lists, and text search; allowed fields; validation; index implications; protection against expensive queries. 5. Sorting: allowed fields, direction, default order, and stable tie-breaks. 6. Limits: default and maximum page sizes. 7. Response shape: data, next cursor, previous link, and a headers alternative. Deliver the specification, example requests and responses, database queries for my database, tests for edge cases (empty page, last page, deleted rows, invalid cursor), and a migration note if I already have offset pagination.
Fill in before use
Optional: type your details and the prompt above updates. Nothing is saved or sent.
Replace each bracketed placeholder with your own details, then paste into Any AI or another assistant.