This covers the three main pagination approaches you'll actually need: offset/limit for simple cases, cursor-based for feeds and infinite scroll, and keyset for massive datasets where offset breaks down. The reference guides include working examples in Node.js and Python with SQLAlchemy, plus specific patterns for search results and response formatting. The best practices are solid reminders, like capping page sizes at 100 and never using offset pagination on billions of rows. It's a practical reference when you're building an API and need to pick the right strategy without overthinking it. The code examples are clean and include the pagination metadata structure you'd actually want to return.

skills.sh installs
495
GitHub stars
379
last updated
Aug 21, 2026

Install

$ npx -y skills add aj-geddes/useful-ai-prompts --skill api-pagination --agent claude-code

Installs into .claude/skills of the current project.

Files

API Pagination

Table of Contents

Overview

Implement scalable pagination strategies for handling large datasets with efficient querying, navigation, and performance optimization.

When to Use

  • Returning large collections of resources
  • Implementing search results pagination
  • Building infinite scroll interfaces
  • Optimizing large dataset queries
  • Managing memory in client applications
  • Improving API response times

Quick Start

Minimal working example:

// Node.js offset/limit implementation
app.get('/api/users', async (req, res) => {
  const page = parseInt(req.query.page) || 1;
  const limit = Math.min(parseInt(req.query.limit) || 20, 100); // Max 100
  const offset = (page - 1) * limit;

  try {
    const [users, total] = await Promise.all([
      User.find()
        .skip(offset)
        .limit(limit)
        .select('id email firstName lastName createdAt'),
      User.countDocuments()
    ]);

    const totalPages = Math.ceil(total / limit);

Sponsors

Details

Repository
github.com/aj-geddes/useful-ai-prompts
Categories
Backend & APIs, AI & Agent Building, Debugging
First seen
Jun 3, 2026

More from aj-geddes/useful-ai-prompts

All 258
1aj-geddes avatarnosql-database-designaj-geddes/useful-ai-promptsDesign NoSQL database schemas for MongoDB and DynamoDB. Use when modeling document structures, designing collections, or planning NoSQL data architectures.492skills.sh installs
2yoanbernabeu avatarsupabase-report-compareyoanbernabeu/supabase-pentest-skillsCompare two security audit reports to track remediation progress and identify new vulnerabilities.491skills.sh installs
3manutej avatarredis-state-managementmanutej/luxor-claude-marketplaceComprehensive guide for Redis state management including caching strategies, session management, pub/sub patterns, distributed locks, and data structures490skills.sh installs
4davila7 avatardatabase-schema-designerdavila7/claude-code-templatesDesign robust, scalable database schemas for SQL and NoSQL databases. Provides normalization guidelines, indexing strategies, migration patterns, constraint des489skills.sh installs
5yoanbernabeu avatarsupabase-extract-jwtyoanbernabeu/supabase-pentest-skillsExtract and decode Supabase-related JWTs from client-side code, cookies, and local storage patterns.487skills.sh installs
6secondsky avatarpayment-gateway-integrationsecondsky/claude-skillsIntegrates payment processing with Stripe, PayPal, or Square including subscriptions, webhooks, and PCI compliance. Use when implementing checkout flows, recurr469skills.sh installs