-
Notifications
You must be signed in to change notification settings - Fork 73
Sorting Pagination and Sparse Fieldsets
Thomas Pollet edited this page Mar 8, 2026
·
1 revision
- Applies to: Flask and FastAPI
- Best sources:
safrs/request.py,safrs/jsonapi_context.py,tests/test_fastapi_parity_semantics.py - Related pages: Filtering, Content Types and Errors, Configuration Reference
Use sort= with one or more fields:
sort=namesort=name,-created
The FastAPI parity tests also assert multi-field sorting and the default fallback sort order by id when no explicit sort is provided.
Use:
page[offset]page[limit]
Example:
GET /Orders?page[offset]=20&page[limit]=10
SAFRS also supports:
page[number]page[size]
These are translated to offset/limit internally.
Example:
GET /Orders?page[number]=2&page[size]=5
That means “page 2 with 5 items per page”, which starts at offset 5.
Relationship collections support relationship-scoped page parameters:
page[items][limit]page[items][offset]page[items][number]page[items][size]
The exact relationship name replaces items.
Use fields[TYPE]=... to restrict the serialized attributes for a type:
GET /Order?fields[Order]=Id,ShipName
SAFRS also recognizes exclude for excluding named relationships from include-heavy responses.
Example:
GET /Order?include=Customer,Employee&exclude=Orders
Pagination behavior is shaped by configuration such as:
DEFAULT_PAGE_LIMITMAX_PAGE_LIMITMAX_PAGE_OFFSET
- Home
- Installation
- Quickstart (Flask)
- Quickstart (FastAPI)
- JSON:API Basics
- Relationships and Includes
- Filtering
- Sorting, Pagination, and Sparse Fieldsets
- Content Types and Errors
- Bulk Requests
- RPC / Custom Methods
- Customization
- Security and Access Control
- Stateless Endpoints / JABase
- Performance
- Examples
- Existing Databases (Legacy)
- PostGIS / GeoAlchemy2
- Docker / Deployment
- Troubleshooting
- Reference: SAFRSBase
- Reference: SAFRSBase Customization