REST API Sorting data
REST API Sorting data
The output from the REST API can be sorted by any field in ascending or descending order, whether you display it or not, by adding a sort= parameter to the api.
You can:
- add multiple sort fields, separated by a '+' as long as the fields are recognized for the endpoint
- sort in descending order by prefacing the field name with a '-'.
Examples of sorting data are:
- https://127.0.0.1/api/v1/patrons?sort=company - sort patron data by company
- https://127.0.0.1/api/v1/patrons?sort=-company - sort patron data by company in DESCENDING order
- https://127.0.0.1/api/v1/patrons?sort=last_name+first_name - sort patron data by last name, then first name
- https://127.0.0.1/api/v1/patrons?sort=last_name+-first_name - sort patron data by last name, then first name in DESCENDING order
- https://127.0.0.1/api/v1/events?sort=year+title+-first_performance_date - sort event data by year, title and then first performance date in DESCENDING order