DEV Community

Discussion on: Why some API response codes are subjective ?

Collapse
 
philipalexanderwallin profile image
PhilipAlexanderWallin

Usually a list of resources in a REST API is referred to as a collection.

I would say 200 OK is correct here, some might argue that it should be 404, but I believe that is semantically incorrect. You did a request for resources, the search went fine, but you found 0 resources to return. 404 would to me mean that the concept "products" doesn't exist, which would make sense if it was a dynamic collection which was yet to be created. Returning an empty list also makes the life of the consumer of the API easier, as he would otherwise need to have a special case for no results found.