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
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.