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

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

    404 would be a more common practice one. Its for Resource Not Found. In your case the particular URL is not found.

    400 is generally used for Bad Request. You can use this one for any bad request. For eg. MissingRequiredQueryParameter, InvalidInput.

提交回复
热议问题