Documentation Index
Fetch the complete documentation index at: https://docs.apivalk.com/llms.txt
Use this file to discover all available pages before exploring further.
Route Configuration
To enable sorting for a specific route, you use thesorting() method on the Route object. This defines which fields can be used for sorting in the request.
Sort object just defines that a field is “sortable”.
Usage in Controller
When a route has sorting enabled, you can access the resolved sortings from the request via thesorting() method, which returns an SortBag.
Client-Side Usage
Apivalk supports sorting using theorder_by query parameter. Clients can specify multiple fields and their sort direction using + (ascending, default) or - (descending) prefixes, separated by commas.
Example: sort by name ascending and then by id descending
GET /pets?order_by=name,-id
Validation
RequestValidationMiddleware rejects any sort field that isn’t declared in the route’s sorting([...]) list. A request like GET /pets?order_by=hacked_field returns 422 Unprocessable Entity with a validation error on the order_by parameter. Routes without any declared sortings skip this check entirely.
OpenAPI Documentation
When you configure sortings on a route, Apivalk automatically generates the corresponding OpenAPI documentation:- An
order_byquery parameter of typestring. - The documentation describes the supported fields and the usage of
+/-prefixes.