I am a Full stack .NET Developer, I like to work with C#, Asp.Net Core, SQL, Mongo DB, Azure, JavaScript...
Always eager to learn new technologies. I am here to share, ask & eventually learn.
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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks, When you say
collection
do you meanTable
in Database ?Also based on filter if search: /products?search= returns empty array then should I return
200 OK
?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.