rest - on POST what if entity exists - what is the correct response -


i have restful api 1 can get nodes , post nodes - basic stuff.

my "problem" this:

when user posts new node, , node exists. should return

  1. 400 bad request
  2. 409 conflict
  3. 200 , existing node

im leaning towards 200 , returning existing node. 409 , letting user correct node seems more "correct" if will.

what "best practice" in matter, restful api's?

the expected result of post creation of new resource along 201 created status code. returning 200 ok not appropriate because request not success. see rfc:

200 ok

the request has succeeded. information returned response dependent on method used in request, example:

get entity corresponding requested resource sent in response;

head entity-header fields corresponding requested resource sent in response without message-body;

post an entity describing or containing result of action;


was there wrong request? no. 400 bad request not appropriate either.


409 conflict

the request not completed due conflict current state of resource. this code allowed in situations expected user might able resolve conflict , resubmit request. response body should include enough

is user able resolve conflict? yes, probably. if conflict arises example because username taken, can return error message user can pick username , resolving conflict.

i go 409.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -