404 Not Found or Bad Request?

前端 未结 2 2070
南旧
南旧 2021-02-05 04:18

Let\'s say that we have the following REST call:

GET api/companies/5 

(get company with id 5)

If company \'5\' doesn\'t exist,

2条回答
  •  时光取名叫无心
    2021-02-05 04:44

    404 may cause a confusion - is the resource missing or is the actual URL incorrect?

    I'd personally go for the 422 code:

       The 422 (Unprocessable Entity) status code means the server
       understands the content type of the request entity (hence a
       415(Unsupported Media Type) status code is inappropriate), and the
       syntax of the request entity is correct (thus a 400 (Bad Request)
       status code is inappropriate) but was unable to process the contained
       instructions.  For example, this error condition may occur if an XML
       request body contains well-formed (i.e., syntactically correct), but
       semantically erroneous, XML instructions.
    

提交回复
热议问题