Should a RESTful API return 400 or 404 when passed an invalid id

后端 未结 6 1913
伪装坚强ぢ
伪装坚强ぢ 2020-12-13 06:02

When building a RESTful API and a user provides an id of resource that does not exist, should you return 404 Not Found or 400 Bad Request

6条回答
  •  生来不讨喜
    2020-12-13 06:18

    404 Not Found is the proper answer I think, 400 is more about the body of the requests and not the resource identifier, so for example you can send that by validation errors.

提交回复
热议问题