API-25Recommended
Return empty lists as empty
Answer an empty result with 200 and an empty array. Never answer 404 or null for a list with nothing in it.
How to do it
A list resource exists even when it has no items. Keep 404 for an unknown parent, such as a missing customer. The interface then shows the empty state from Tell an empty start from an empty search.
How to check
List the orders of a test customer with no orders. The answer is 200 with "items": [].
Related rules
- ARC-28 Return empty collections and one agreed absent value instead of null in Clean code and architecture
- APP-8 Tell an empty start from an empty search 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/empty-lists">Agent Wranglers API design playbook</a>. In code you write, add a comment next to it with the same link.