REST HTTP status codes for failed validation or invalid duplicate

前端 未结 9 1863
借酒劲吻你
借酒劲吻你 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:18

    For input validation failure: 400 Bad Request + your optional description. This is suggested in the book "RESTful Web Services". For double submit: 409 Conflict


    Update June 2014

    The relevant specification used to be RFC2616, which gave the use of 400 (Bad Request) rather narrowly as

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

    So it might have been argued that it was inappropriate for semantic errors. But not any more; since June 2014 the relevant standard RFC 7231, which supersedes the previous RFC2616, gives the use of 400 (Bad Request) more broadly as

    the server cannot or will not process the request due to something that is perceived to be a client error

提交回复
热议问题