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

Brian is a software architect and technology leader living in Niagara Falls with 13+ years of development experience. He is passionate about automation, business process re-engineering, and building a better tomorrow.

Brian is a proud father of four: two boys, and two girls and has been happily married to Crystal for more than ten years. From time to time, Brian may post about his faith, his family, and definitely about technology.