API Pagination

API Pagination

Guides an AI agent to implement API pagination for large datasets using offset/limit, cursor-based and keyset strategies with response formats and search pagination.

Skill files9 files

references/

scripts/

templates/

SKILL.md105 lines
1
---
2
name: api-pagination
3
description: >
4
Implement efficient pagination strategies for large datasets using
5
offset/limit, cursor-based, and keyset pagination. Use when returning
6
collections, managing large result sets, or optimizing query performance.
7
---
8
9
# API Pagination
10
11
## Table of Contents
12
13
- [Overview](#overview)
14
- [When to Use](#when-to-use)
15
- [Quick Start](#quick-start)
16
- [Reference Guides](#reference-guides)
17
- [Best Practices](#best-practices)
18
19
## Overview
20
21
Implement scalable pagination strategies for handling large datasets with efficient querying, navigation, and performance optimization.
22
23
## When to Use
24
25
- Returning large collections of resources
26
- Implementing search results pagination
27
- Building infinite scroll interfaces
28
- Optimizing large dataset queries
29
- Managing memory in client applications
30
- Improving API response times
31
32
## Quick Start
33
34
Minimal working example:
35
36
```javascript
37
// Node.js offset/limit implementation
38
app.get('/api/users', async (req, res) => {
39
const page = parseInt(req.query.page) || 1;
40
const limit = Math.min(parseInt(req.query.limit) || 20, 100); // Max 100
41
const offset = (page - 1) * limit;
42
43
try {
44
const [users, total] = await Promise.all([
45
User.find()
46
.skip(offset)
47
.limit(limit)
48
.select('id email firstName lastName createdAt'),
49
User.countDocuments()
50
]);
51
52
const totalPages = Math.ceil(total / limit);
53
54
res.json({
55
data: users,
56
pagination: {
57
page,
58
limit,
59
total,
60
totalPages,
61
hasNext: page < totalPages,
62
// ... (see reference guides for full implementation)
63
```
64
65
## Reference Guides
66
67
Detailed implementations in the `references/` directory:
68
69
| Guide | Contents |
70
|---|---|
71
| [Offset/Limit Pagination](references/offsetlimit-pagination.md) | Offset/Limit Pagination |
72
| [Cursor-Based Pagination](references/cursor-based-pagination.md) | Cursor-Based Pagination |
73
| [Keyset Pagination](references/keyset-pagination.md) | Keyset Pagination |
74
| [Search Pagination](references/search-pagination.md) | Search Pagination |
75
| [Pagination Response Formats](references/pagination-response-formats.md) | Pagination Response Formats |
76
| [Python Pagination (SQLAlchemy)](references/python-pagination-sqlalchemy.md) | Python Pagination (SQLAlchemy) |
77
78
## Best Practices
79
80
### ✅ DO
81
82
- Use cursor pagination for large datasets
83
- Set reasonable maximum limits (e.g., 100)
84
- Include total count when feasible
85
- Provide navigation links
86
- Document pagination strategy
87
- Use indexed fields for sorting
88
- Cache pagination results when appropriate
89
- Handle edge cases (empty results)
90
- Implement consistent pagination formats
91
- Use keyset for extremely large datasets
92
93
### ❌ DON'T
94
95
- Use offset with billions of rows
96
- Allow unlimited page sizes
97
- Count rows for every request
98
- Paginate without sorting
99
- Change sort order mid-pagination
100
- Use deep pagination without cursor
101
- Skip pagination for large datasets
102
- Expose database pagination directly
103
- Mix pagination strategies
104
- Ignore performance implications
105

© AJ Geddes · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 13,694 prompts

More by @OpenSourceBuffGuy

See all
A summer evening in Seoul, shot like a home video prompt image

A summer evening in Seoul, shot like a home video

Generates a 30-second home-video style clip of a young woman on a summer evening in a Seoul neighborhood, shot like early-2000s camcorder footage with small accidents and natural sound only.

video-prompt, home-video, vlog, handheld, film-grain, candid, korea, multi-shot, ugc-video, lip-sync, guardrails, seedance, long-form, natural-light, vintage, muted-colors, cityscape, for-content-creators, sound-effects, structured-output, summer, timed-beats

Woman in satin bustier taking indoor selfie prompt image

Woman in satin bustier taking indoor selfie

Recreates a reference smartphone selfie as a new adult woman in a luxury living room, matching crop, light and styling while leaving out all on-screen text and icons.

image-prompt, json-prompt, gpt-image, reference-image, selfie, portrait, woman, photorealistic, smartphone-photo, natural-light, fashion, jewelry, hairstyles, interior-design, negative-prompt, structured-output, vertical-format, close-up, social-media-graphic, long-form, advanced

Chest-up editorial portrait in oversized black blazer prompt image

Chest-up editorial portrait in oversized black blazer

Turns a reference photo into a chest-up fashion editorial portrait in an oversized black blazer, with a locked identity and soft side sunlight on a white wall.

image-prompt, gpt-image, reference-image, face-reference, portrait, woman, editorial, fashion, fashion-shoot, medium-shot, natural-light, white-background, vertical-format, photorealistic, luxury, negative-prompt, guardrails, photography, for-photographers, for-artists, quick, bokeh, headshot, soft-lighting

Reviews

Loading reviews…

Discussion

Loading comments…