Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Should a RESTful API return a 200 OK response when requesting a list of posts for a category that does not exist?

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

  1. 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
  2. You return 204 code which equates to ‘No Content’ in RFC specifications.

Hope this works. Thanks.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading