What is the correct HTTP status code for a child entity that is not found?

前端 未结 3 1851
说谎
说谎 2020-12-09 23:18

Say I\'ve got a resource

/Products/123

And each Product has an associated Supplier entity in the back end databas

3条回答
  •  [愿得一人]
    2020-12-09 23:32

    Hello I would use the 404 as mentioned prior:

    6.5.4. 404 Not Found

    The 404 (Not Found) status code indicates that the origin server did not find a current representation for the target resource or is not willing to disclose that one exists. A 404 status code does not indicate whether this lack of representation is temporary or permanent; the 410 (Gone) status code is preferred over 404 if the origin server knows, presumably through some configurable means, that the condition is likely to be permanent.

    Because the product that you are looking for exists, but the Supplier ID not, so basically is like we are looking for you in a different city, you exist but not in that city, so we will say, hey we did not found you.

    I believe that supplier and product they have a relationship and it is a hard relationship, that a product can not exist if you don't have a supplier for that product, so that means you can not update a product if you don't know it is supplier.

提交回复
热议问题