Tuesday, August 28, 2012

POST vs PUT in REST

In designing REST APIs, it's often said to map POST to Create operations and PUT to update operations, but most people don't really explain why. Here's a good explanation I found:
http://jcalcote.wordpress.com/2008/10/16/put-or-post-the-rest-of-the-story/

In a nutshell:
  • Browsers treat PUTs as idempotent operations, and will not hesitate to call the server again with the same URL if the user hit the "back" button on the browser.
  • Browsers does not treat POSTs as idempotent operations, so when the user hits the "back" button on the browser, it asks the user if he wants to submit the data again.
Since it is not possible for the server to ensure idempotency when asked to create something new (i.e. it wouldn't know if the 2nd, 3rd call etc. are genuine calls to create more entries with the same data), POST is use for creating new entries.

No comments:

Post a Comment