So, I have an RESTful API on a blog site (WordPress, but that’s irrelevant). I understand that if, for example, there are 0 posts in the category news, the route /posts/by-category/news/?limit=100&offset=0 should return a 200 OK response with a body like {total: 0, items: []}, which is quite logical. But what if the category news does not exist? Should the route still return a 200 OK response with {total: 0, items: []} body, or shall it return a 404 Not Found response?
>Solution :
Extending on the answer given by Dhaval.
As per RFC specs response codes 2xx and 4xx have different meanings.
Good read about that: HTTP Get with 204 No Content: Is that normal
To conclude it depends on how you run your web app.
- Route one could be your return 200 code. and then show a message basis on the length of the result set returned in API call
- You return 204 code which equates to ‘No Content’ in RFC specifications.
Hope this works. Thanks.