Skip to content
Skills Library
Programming · Learning & explanation

pagination

/pagination

API pagination patterns. Offset-based, cursor-based, keyset pagination. Filtering, sorting, and page metadata. REST and GraphQL pagination implementations. USE WHEN: user mentions "pagination", "paginate", "cursor", "offset", "page size", "next page", "infinite scroll API", "list endpoint" DO NOT USE FOR: frontend infinite scroll UI - use frontend framework skills; database query optimization - use database skills

Licence
MIT
Last repository change
21.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 21.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

API pagination patterns. Offset-based, cursor-based, keyset pagination. Filtering, sorting, and page metadata. REST and GraphQL pagination implementations. USE WHEN: user mentions "pagination", "paginate", "cursor", "offset", "page size", "next page", "infinite scroll API", "list endpoint" DO NOT USE FOR: frontend infinite scroll UI - use frontend framework skills; database query optimization - use database skills

Triggers from the description

paginationpaginatecursoroffsetpage sizenext pageinfinite scroll APIlist endpoint
Original author description

API pagination patterns. Offset-based, cursor-based, keyset pagination. Filtering, sorting, and page metadata. REST and GraphQL pagination implementations. USE WHEN: user mentions "pagination", "paginate", "cursor", "offset", "page size", "next page", "infinite scroll API", "list endpoint" DO NOT USE FOR: frontend infinite scroll UI - use frontend framework skills; database query optimization - use database skills

How it works

  1. Cursor-Based (recommended for large datasets)
  2. Offset-Based (simple, good for small datasets)
  3. Filtering and Sorting
  4. Spring Boot (Pageable)
  5. Comparison
  6. Anti-Patterns
  7. Production Checklist
Original SKILL.md headings · 124 lines, 498 words
SKILL.md preview
---
name: pagination
description: |
  API pagination patterns. Offset-based, cursor-based, keyset pagination.
  Filtering, sorting, and page metadata. REST and GraphQL pagination
  implementations.

  USE WHEN: user mentions "pagination", "paginate", "cursor", "offset",
  "page size", "next page", "infinite scroll API", "list endpoint"

  DO NOT USE FOR: frontend infinite scroll UI - use frontend framework skills;
  database query optimization - use database skills
allowed-tools: Read, Grep, Glob, Write, Edit
---
# Pagination

## Cursor-Based (recommended for large datasets)

```typescript
app.get('/api/products', async (req, res) => {
  const limit = Math.min(parseInt(req.query.limit as string) || 20, 100);
  const cursor = req.query.cursor as string | undefined;

  const where: any = {};
  if (cursor) {
    where.id = { gt: cursor };
  }

  const items = await db.product.findMany({
    where,
    take: limit + 1, // Fetch one extra to check hasMore
    orderBy: { id: 'asc' },
  });

  const hasMore = items.length > limit;
  if (hasMore) items.pop();

  res.json({
    data: items,
    pagination: {
      hasMore,
      nextCursor: hasMore ? items[items.length - 1].id : null,
    },
  });
});
```

## Offset-Based (simple, good for small datasets)

```typescript
app.get('/api/products', async (req, res) => {
  const page = Math.max(parseInt(req.query.page as string) || 1, 1);
  const limit = Math.min(parseInt(req.query.limit as string) || 20, 100);
  const offset = (page - 1) * limit;

  const [items, total] = await Promise.all([
    db.product.findMany({ skip: offset, take: limit, orderBy: { createdAt: 'desc' } }),
    db.product.count(),
  ]);

  res.json({
    data: items,
    pagination: {
      page, limit, total,
      totalPages: Math.ceil(total / limit),
      hasMore: offset + items.length < total,
    },
  });
});
```

## Filtering and Sorting

```typescript
app.get('/api/products', async (req, res) => {
  const { sort = 'createdAt', order = 'desc', category, minPrice, maxPrice, search } = req.query;

  const where: any = {};
  if (category) where.category = category;
  if (minPrice || maxPrice) {
    where.price = {};
    if (minPrice) where.price.gte = parseFloat(minPrice as string);
    if (maxPrice) where.price.lte = parseFloat(maxPrice as string);
  }
  if (search) where.name = { contains: search, mode: 'insensitive' };

  const items = await db.product.findMany({
    where,
    orderBy: { [sort as string]: order },
    take: limit,
    skip: offset,
  });

  res.json({ data: items, pagination: { /* ... */ } });
});
```

## Spring Boot (Pageable)

```java
@GetMapping("/products")
public Page<ProductDto> list(
    @RequestParam(defaultValue = "0") int page,
    @RequestParam(defaultValue = "20") int size,
    @RequestParam(defaultValue = "createdAt,desc") String[] sort) {

    Pageable pageable = PageRequest.of(page, Math.min(size, 100),
        Sort.by(Sort.Direction.fromString(sort[1]), sort[0]));
    return productRepo.findAll(pageable).map(mapper::toDto);
}
```

## Comparison

| Strategy | Pros | Cons | Best For |
|----------|------|------|----------|
| Offset | Simple, jump to page | Slow on large tables, skip drift | Admin panels, small datasets |
| Cursor | Fast, stable with inserts | Can't jump to page N | Feeds, infinite scroll, large datasets |
| Keyset | Fast, no skip drift | Complex multi-column sort | Time-series, ordered data |

## Anti-Patterns

| Anti-Pattern | Fix |
|--------------|-----|
| No max page size | Cap `limit` (e.g., max 100) |
| COUNT(*) on huge tables | Use cursor pagination, skip total count |
| Offset on millions of rows | Use cursor or keyset pagination |
| Returning all fields | Select only needed fields, support `fields` param |
| No default sorting | Always define default sort for stable results |

## Production Checklist

- [ ] Maximum page size enforced (e.g., 100)
- [ ] Default sort order defined
- [ ] Cursor pagination for large/growing datasets
- [ ] Input validation on page/limit/sort params
- [ ] Consistent response envelope (`data`, `pagination`)

Versions

RepositoryScoreLicence
This page · claude-dev-suite/claude-dev-suite100MIT
thedaviddias/front-end-checklist100MIT
rshankras/claude-code-apple-skills100MIT
Esposter/Esposter90Apache-2.0

Database snapshot: 13.11.2026 · package version d711420254b3 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100api-pagination
    Implements efficient API pagination using offset, cursor, and keyset strategies for large datasets. Use when building paginated endpoints, implementing infinite scroll, or optimizing database queries for collections.
  • 90pagination-performance
    Paginate large result sets so page cost stays constant by using keyset (cursor) pagination instead of OFFSET, with a stable, encoded cursor. Use when deep pages get slow, an infinite scroll drifts or duplicates rows, or OFFSET grows with page depth.
  • 100api-pagination-filtering-sorting
    Use this skill when designing cursor-based pagination, offset pagination, dynamic filters, and multi-field sorting on REST APIs.
  • 100response-design-and-pagination
    This skill should be used when the user is designing API response formats, implementing pagination (cursor, offset, keyset), creating list endpoints, designing response envelopes, implementing expandable/embeddable objects, or structuring API output. Covers Stripe-style cursor…
  • 95relay-pagination
    Use when relay pagination with cursor-based pagination, infinite scroll, load more patterns, and connection protocols.
  • 100api-pagination-filtering-sorting
    HTTP query parameter conventions for pagination, filtering, sorting, and search with standardized response metadata. Use when designing list endpoints or building repositories that turn query params into SQL.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.