Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the best Http code to identify idempotent operation conflict

i develop res service at which it take unique id parameter each call, but when the same id used more than once it should retrieve the same response was retrieved the first time and status code specify error, i am looking for the best status code for that , some post use "409 Conflict" and some "406 Not Acceptable", which to use ?

like image 307
Melad Basilius Avatar asked Mar 12 '17 10:03

Melad Basilius


2 Answers

409 is better, because 406 is mostly used to represent header not acceptable.

406 Not Acceptable The requested resource is capable of generating only content not acceptable according to the Accept headers sent in the request.

409 (Conflict) means your request is duplicated.

409 Conflict Indicates that the request could not be processed because of conflict in the request, such as an edit conflict between multiple simultaneous updates.

like image 98
Asoul Avatar answered Oct 13 '22 03:10

Asoul


I would like to put a different opinion on the table. "Why should we return 409 always and bother client to handle these scenarios? Why should client be bothered about if item was created as part of current request or one of past tries?"

I feel for a simple scenarios like "POST on collection to create a resource instance" client could be simplified if server returns 201 even in the case of idempotent response.

However, we should also make sure that this simplification does not create confusion in some scenarios like: Resource was created with initial version V1 by POST request from a client. This resource then get updated and moves to version V2. Now for some reason the initial client retries POST request with the same Idempotency token. I believe the later one should be returned as 409, since this is a conflict.

POST is expected to create an initial version of the resource with the data present in request. Since this is duplicate request, we would rather fetch existing resource instance and return to client. That resource state may not have all fields as specified in the create request, and hence conflicting.

like image 39
Rajeev Ranjan Avatar answered Oct 13 '22 01:10

Rajeev Ranjan