Skip to main content

Pagination, filtering, and sorting

Pagination, filtering and sorting

Pagination

Page pagination

Use page and limit:
Example response snippet:

Offset pagination

Use offset and limit:
Example response snippet:

Cursor pagination

Example response snippet:

Sorting

Use ’+’ (ASC) or ’-’ (DESC) as a prefix for each field. If not specified, default is ASC. Multiple fields can be separated by a comma.
In Apivalk, this order_by parameter automatically populates the sorting() bag on the request object, based on the fields allowed in the Route definition. Any field not declared via Route::sorting([...]) (or AbstractResource::availableSortings()) is rejected by the validation middleware with a 422.

Filtering

Filtering allows clients to narrow down results by specifying conditions on fields. A field carries the operator in brackets, so one field can take several conditions at once. Example: retrieve all plugs with phase AC:
Example: a price range on a single field, rather than two invented field names:
Where a field accepts a single operator, the flat form is the shorter equivalent: