api-pagination_skill

This skill helps you implement scalable API pagination using offset, cursor, and keyset strategies to optimize large datasets.
  • TypeScript

52

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill secondsky/claude-skills --skill api-pagination

  • SKILL.md2.1 KB

Overview

This skill implements efficient API pagination using offset, cursor, and keyset strategies for large datasets. It provides production-ready patterns and response formats to support paginated endpoints, infinite scroll, and performance-sensitive collection queries. The implementation is TypeScript-friendly and designed for integration with modern stacks like Cloudflare, React, and Tailwind-based frontends.

How this skill works

The skill supplies three pagination strategies: offset/limit for simple pages, cursor pagination for infinite scroll and real-time feeds, and keyset pagination for high-performance access to large collections. Each strategy includes request parsing, safe limits, and a consistent response shape with data, pagination metadata, and navigation links. Cursor logic encodes/decode opaque cursors; keyset relies on indexed sort keys to avoid OFFSET scans.

When to use it

  • Offset/limit when dataset is small and UI requires numbered pages.
  • Cursor pagination for infinite scroll or APIs that must provide stable forward traversal.
  • Keyset pagination for very large tables where OFFSET is too slow.
  • When you need consistent response metadata and navigation links for clients.
  • When you must enforce maximum page sizes and protect the database from heavy queries.

Best practices

  • Enforce a reasonable max limit (e.g., 100) to prevent heavy responses.
  • Prefer cursor or keyset for large datasets to achieve O(1) performance.
  • Index the fields used for sorting and keyset lookups.
  • Avoid count queries on very large tables; supply approximate totals or defer expensive counts.
  • Encode cursors opaquely (e.g., base64) and validate them on input.

Example use cases

  • Products listing endpoint with offset pagination and total pages for e-commerce.
  • Social feed using cursor pagination to support infinite scrolling in a client app.
  • Audit log or events listing using keyset pagination to page through millions of rows quickly.
  • API that returns standardized pagination metadata and HATEOAS-style links for navigation.
  • Protecting backend resources by capping page size and preventing unbounded requests.

FAQ

Choose cursor when you need stable, performant forward traversal (infinite scroll) or when OFFSET becomes slow for large offsets.

How do I generate a safe cursor?

Use an opaque encoding like base64 of the last item's indexed key or id, and validate/normalize it server-side before using it in queries.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational