4

Simple question:

I have a POST endpoint which expects some text input. The text input must not be longer than x characters. If it is I'll respond with an error message.

But which HTTP status code will be the correct one?

0.4.4 403 Forbidden

The server understood the request, but is refusing to fulfill it. Authorization will not help and the request SHOULD NOT be repeated. [..]

10.4.7 406 Not Acceptable

The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request.

10.4.18 417 Expectation Failed

The expectation given in an Expect request-header field [..] could not be met by this server [..]

Source: w3.org

boop
  • 7,413
  • 13
  • 50
  • 94

1 Answers1

3

I guess that's existed question. Shortly the proper HTTP Code is 400 + optional description.

You can checkout more detailed answer here: REST HTTP status codes for failed validation or invalid duplicate

Community
  • 1
  • 1
Andriy Ivaneyko
  • 20,639
  • 6
  • 60
  • 82