Order API responses by any numerical, string, or boolean field using _sort and _order. Values are sorted with type-aware comparison, ensuring proper numeric order instead of alphabetical bugs.
Customize sort target and direction to test across collections:
id in desc order.GET /posts?_sort=id&_order=descMany mock servers fail by treating all fields as strings, causing 10 to sort before 2. Playground inspects underlying data types:
| Data Type | Sort Strategy | ASC Order Example | DESC Order Example |
|---|---|---|---|
| Numeric (ID, Price, Stock) | Numeric comparison (a - b) | 1, 2, 9, 10, 100 | 100, 10, 9, 2, 1 |
| String (Title, Name, Email) | Case-insensitive localeCompare | Alice, Bob, Charlie | Charlie, Bob, Alice |
| Boolean (Completed, InStock) | Falsy values first in ASC | false, false, true, true | true, true, false, false |
DataGrid and table sorting patterns for React and modern web apps: