How should a REST Endpoint Handle No Results?

Sharing is Caring

Handling no results in a collection endpoint and at a singular resource can be a bit of a tricky situation.

When a collection endpoint has no resources to return it should return a valid response body and a 200 response code. The caller needs to handle the list being empty, there’s no error though if there’s legitimately no items.

If it’s a single resource request and there’s no resource to return, you should return a 404 or Item Not Found Error. If there’s an item but the user doesn’t have access to it, then you should return a 401 or 403 error.

Sharing is Caring

Leave a Reply

Your email address will not be published.