Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

404 vs 200 for relative entities, RESTful

Tags:

rest

http

What status code is more appropriate for a case when relation is not existing?

For instance, /articles/1/comments/4, with this call you will get commentID 4 from articleID 1. But what if commentID 4 not exists in this relation, what should API returned, 404 or 200 ?

EDIT: Let me clarify what do I meant.

The thing is, you can interpret 404 like resource not exists from another point of view, for instance: /articles/1/builders/3. You don't have such route at all in your application! Your application does have handler for such url completely. But /articles/1/comments/4. You have such route in app, you have handler (controller). And yeah, I know that this url reflect relationship between comments and articles, and this is why it is tricky. Because comment with ID 4 might exists in your DB even if it does not belong to article. Then if you have such route in application you may say that from http protocol point of view you have such resource, but based on your application logic, you may say that such comment not belongs to specified article.

like image 420
user1016265 Avatar asked Dec 03 '25 02:12

user1016265


1 Answers

It should be 404 (of course). You requested for a particular resource with ID equal to 4 and did not find it.

like image 101
Opal Avatar answered Dec 05 '25 17:12

Opal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!