kinto icon indicating copy to clipboard operation
kinto copied to clipboard

feat: Add offset-based pagination support

Open sherlock2215 opened this issue 1 month ago • 1 comments

Add Offset-Based Pagination Support

Problem

Currently, Kinto only supports token-based pagination which requires sequential access to records. Users cannot jump directly to specific record positions (e.g., records 100-120) without paging through all previous records.

Solution

This PR adds support for _offset parameter alongside the existing token-based pagination, allowing direct access to any record position.

Changes

  • New _offset parameter: Allows specifying starting position for records
  • Backward compatible: Existing token-based pagination continues to work unchanged
  • Enhanced response format: Includes pagination metadata for offset requests
  • Manual offset handling: Implements offset slicing for memory backend

Key Features

  1. Direct Access: GET /records?_limit=20&_offset=100 returns records 100-119 directly
  2. Pagination Metadata: Response includes pagination object with limit, offset, total, has_more
  3. Next Page URLs: Automatically generated with correct offset values
  4. Priority System: Offset takes precedence over token when both are provided

API Examples

# Offset pagination
GET /records?_limit=20&_offset=100

# Response
{
  "data": [...],
  "pagination": {
    "limit": 20,
    "offset": 100,
    "total": null,
    "has_more": true
  },
  "next": "/records?_limit=20&_offset=120"
}

# Backward compatibility maintained
GET /records?_limit=20&_token=abc123  # Still works

sherlock2215 avatar Nov 14 '25 00:11 sherlock2215

This addresses the feature request in #3403

sherlock2215 avatar Nov 14 '25 00:11 sherlock2215