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

前端 未结 3 1862
说谎
说谎 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:46

    I don't believe that there is a correct answer for this question (unless some REST purist can shed some light) but we currently use (or abuse...) HTTP 400 (Bad Request) with an additional HTTP Header explaining the error (i.e. X-Error: Invalid supplier ID). However a HTTP 422 would also be a good alternative. Statuses 404 or 409 would be confusing since there is no clear way to specify that the response is about a sub-resource.

提交回复
热议问题