Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's a proper response status code to REST POST request when duplicate is found?

In my RESTful API client might try to post information that is already in the database, this is not an error, rather something client can ignore, maybe notify the user about already existing dublicate.

Now i'm returning 409 Conflict and already existing object in the response body. I feel that it's incorrect because:

The request could not be completed due to a conflict with the current state of the resource. This code is only allowed in situations where it is expected that the user might be able to resolve the conflict and resubmit the request. The response body SHOULD include enough information for the user to recognize the source of the conflict. Ideally, the response entity would include enough information for the user or user agent to fix the problem; however, that might not be possible and is not required. via restpatterns.org

and in general, it seems, that 409 is more associated with PUT.

What is the correct response in this case? Could it be 303 See Other and Location header?

like image 729
miceuz Avatar asked Feb 23 '12 13:02

miceuz


People also ask

What is the HTTP status code for duplicate record?

409 Conflict - Client attempting to create a duplicate record, which is not allowed. 410 Gone - The requested resource has been deleted. 411 Length Required - The server will not accept the request without the Content-Length Header.

What is a 204 response code?

The HTTP 204 No Content success status response code indicates that a request has succeeded, but that the client doesn't need to navigate away from its current page.

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 the response code 202 and 204 mean?

200 OK. 201 Created. 202 Accepted. 203 Non-Authoritative Information. 204 No Content.


1 Answers

I'm not sure there is a correct answer. We are returning a 409 with a message that it's a duplicate resource. We also include hypermedia to that resource. It seems you could also use a 400 - Bad Request but that seemed too generic. I could see the 303 also working. I wanted to indicate that there was an error so we went with the 409.

like image 125
suing Avatar answered Oct 16 '22 00:10

suing