You can sort items of most collections thanks to the sort
query parameter.
id
, name
, etc…
Sorting direction (i.e. “ascending” vs “descending”) is indicated through adding a prefix to the name of the property the sorting should be applied to:
Direction | Prefix | Example |
---|---|---|
Descending | "-" (hyphen) | /employees?sort=-familyName : return employees by descending family name. |
Ascending | "+" (plus) or "" (nothing) | /leaves?sort=startsOn : return leaves by ascending start date. |
"%2B"
./employees?sort=familyName,givenName
returns all employees, sorted by ascending family name THEN by ascending given name. In this case, the “Bros” brothers are returned by ascending first name: ‘Luigi (Bros)’, then ‘Mario (Bros)’.
P.S.: Technically, Mario’s and Luigi’s family name should be “Mario”, but it feels wrong for some reason.