API-24Recommended
Sort in a stable order
Sort every list in a documented, stable order, and let clients choose from a fixed set of sort keys.
How to do it
Default to a unique key, such as creation time plus ID, so equal values never swap between pages. Accept a parameter such as sort=-createdAt with an allow-list of fields. Add the ID as the last sort key to any sort the client picks.
How to check
Two identical list requests return items in the same order, and an unlisted sort field gets 400.
Related rules
- APP-35 Sort and filter on the server in Web app interface
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/api-design/lists/sorting">Agent Wranglers API design playbook</a>. In code you write, add a comment next to it with the same link.