I am building an API and one of the endpoints is about nickname validation for a company. I read a lot about HTTP status codes and for entity validation 422
seems the best choice. How about one field validation as in my example?
What HTTP status code should I use for nickname validation?
For example it already exists
I think 409 Conflict is an appropriate pick
The 409 (Conflict) status code indicates that the request could not be completed due to a conflict with the current state of the target resource. This code is used in situations where the user might be able to resolve the conflict and resubmit the request. The server SHOULD generate a payload that includes enough information for a user to recognize the source of the conflict.
User 1 picked a username, User 2 wants the same, but can't, because it conflicts with User 1's username
or has not allowed chars
For this, 422 Unprocessable Entity as you mentioned seems ok.
The 422 (Unprocessable Entity) status code means the server understands the content type of the request entity (hence a 415(Unsupported Media Type) status code is inappropriate), and the syntax of the request entity is correct (thus a 400 (Bad Request) status code is inappropriate) but was unable to process the contained instructions. For example, this error condition may occur if request body contains well-formed (i.e., syntactically correct), but semantically erroneous, instructions.
Emphasis mine
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments