REST HTTP status codes for failed validation or invalid duplicate

前端 未结 9 1859
借酒劲吻你
借酒劲吻你 2020-11-22 13:53

I am building an application with a REST-based API and have come to the point where I am specifying status codes for each requests.

What status code should i send for

9条回答
  •  一整个雨季
    2020-11-22 14:13

    • Failed validation: 403 Forbidden ("The server understood the request, but is refusing to fulfill it"). Contrary to popular opinion, RFC2616 doesn't say "403 is only intended for failed authentication", but "403: I know what you want, but I won't do that". That condition may or may not be due to authentication.
    • Trying to add a duplicate: 409 Conflict ("The request could not be completed due to a conflict with the current state of the resource.")

    You should definitely give a more detailed explanation in the response headers and/or body (e.g. with a custom header - X-Status-Reason: Validation failed).

提交回复
热议问题