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
400 bad request
409 conflict
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:
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.
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
Post a Comment