Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which HTTP response code for "This email is already registered"?

Tags:

rest

http

I'm creating a RESTful API for creating users that enforces unique email addresses:

Successful POST /users: HTTP 201 Created

If I POST the same email address again, what should the response code be? Is 409 Conflict the appropriate response code?

like image 834
thatmarvin Avatar asked Feb 13 '12 22:02

thatmarvin


People also ask

What is a 207 HTTP response?

The HTTP Status Code 207 means that the message body that follows is by default an XML message and can contain a number of separate response codes, depending on how many sub-requests were made.

What HTTP status code for already exists?

The appropriate status code for "Already Exists" would be '409 Conflict'.

What is a 201 response code?

The HTTP 201 Created success status response code indicates that the request has succeeded and has led to the creation of a resource.

What does a HTTP 200 response status mean?

The HTTP 200 OK success status response code indicates that the request has succeeded. A 200 response is cacheable by default. The meaning of a success depends on the HTTP request method: GET : The resource has been fetched and is transmitted in the message body.


1 Answers

Yes, 409 is the most appropriate response code here. Even though you are most likely returning 201 on success, you're still POSTing to a resource which is described as a collection, and POSTing a duplicate email is definitely a conflict with "the current state of the resource" as a collection. You should return a response body with a description of the problem, and hyperlinks to help resolve the problem, if possible.

like image 87
fumanchu Avatar answered Oct 07 '22 18:10

fumanchu