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

后端 未结 6 1901
伪装坚强ぢ
伪装坚强ぢ 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:37

    Is it a valid request? Can the id of the resource exist? Is it formatted as a proper id? Is it syntactically correct? etc.. If so then you can use, 404 Not Found. Otherwise 400 Bad Request is more suitable.

提交回复
热议问题