Sorting
Sorting
Sorting
Sorting is the capability to order results by any field in ascending or descending order. The specification for sorting implementations is:
- APIs SHOULD accept a sortBy query parameter with a field name as the value.
- APIs implementing sorting SHOULD implement stable sorts.
- All GET or POST requests that respond with a list of resources MUST have a default sort and the default sort MUST be specified in API documentation.
- In most cases, default sorting should be createdAtDateTime descending (newest to oldest) using an immutable/incremental field to avoid disruptions of the sort order from pagination.
- The API documentation MUST specify the supported fields for sorting. Specify multiple fields by using a comma as the separator. Each sortable field’s documentation MUST specify the default sort direction.
- APIs MUST support sorting by field names in ascending and descending order. Sorting is ascending by default. To specify a descending sort on a field name, prefix the field name with a ’-‘.
Example:
GET /api/resource?sortBy=-createdAtDateTime,status