404 Not Found or Bad Request?

前端 未结 2 2051
南旧
南旧 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:37

    404 is your best response. According the HTTP RFC, http://www.ietf.org/rfc/rfc2616.txt, a 400 Bad Request means:

    The request could not be understood by the server due to malformed syntax.

    Whereas, a 404 states:

    The server has not found anything matching the Request-URI.

    The entire URI is your resource identifier, and you're not finding a matching resource for that particular identifier.

提交回复
热议问题