Pagination Standards

Skip-offset pagination convention across all services with standardized response format

All list-based endpoints across MQUAD microservices follow a unified pagination contract.

Request Parameters

ParameterTypeDefaultDescription
skipinteger0Number of records to skip (0-based)
limitinteger20Maximum records per page (max: 100)

Response Format

{
  "items": [],
  "total": 100,
  "skip": 0,
  "limit": 20,
  "has_next": true,
  "has_previous": false
}
FieldTypeDescription
itemsarrayThe page of results
totalintegerTotal matching records across all pages
skipintegerCurrent offset
limitintegerCurrent page size
has_nextbooleanMore pages available after this one
has_previousbooleanPrevious pages exist before this one

Implementation

from pydantic import BaseModel
from typing import Generic, TypeVar, List

T = TypeVar("T")

class PaginatedResponse(BaseModel, Generic[T]):
    items: List[T]
    total: int
    skip: int
    limit: int
    has_next: bool
    has_previous: bool

def paginate(query, skip: int, limit: int, total: int) -> PaginatedResponse:
    return PaginatedResponse(
        items=query,
        total=total,
        skip=skip,
        limit=limit,
        has_next=(skip + limit) < total,
        has_previous=skip > 0,
    )

Usage

# First page
GET /responses?skip=0&limit=20

# Second page
GET /responses?skip=20&limit=20

Frontend Integration

The pagination format is designed to work with the AdvanceTable component:

interface PaginatedResponse<T> {
  items: T[];
  total: number;
  skip: number;
  limit: number;
  has_next: boolean;
  has_previous: boolean;
}

All services use this standard. The generic items field simplifies frontend integration regardless of resource type.