ruby on rails - Update via HTTP POST -
there lots of threads on here debating when use http put vs. post. however, clear should possible update records via either method.
without going irrelevant detail, i'd create or update record via post.
if understand correctly, should able achieve based on whether include id of existing record or not in http body. if post includes id, it's update, otherwise it's create request (and newly created record id returned in response).
as such,
put: http://www.database.com/record/99 (with record attributes in http body)
is equivalent to,
post: http://www.database.com/records (with record id=99 , attributes in http body)
my code post works fine creating new records (i.e. when don't include id). when include id in http body ignored, , server performs create, not update.
as such, i'd know, understanding of how post http body interpreted correct?
your interpretation of how post body interpreted incorrect.
the id needs in url recognised update. url specifies resource being updated, not body.
sticking rails convention of post create , put update easier trying fight it. conventions there reason, don't have worry stuff this.
Comments
Post a Comment