ReST: PUT vs POST

Creating REST APIs in a larger team; everyone knows that the difference between  PUT and POST is semantic, but that doesn’t mean it’s not worth paying attention to. Expectations matter, this is similar to variable naming. So general expectation is:
 
POST – creates something. 
PUT – updates something.
 

 
PUT is assumed to be idempotent, so calls after the first should have no additional effect. So in the case of updating a DB, you can imagine something like setting a value associated with a primary key. (See PATCH as well).
 
POST on the other hand is not assumed to be idempotent. So perhaps its appropriate e.g. for adding lines to an open transaction at a retail till, where the same data can usefully be written multiple times.
 
 

Leave a Reply

Your email address will not be published. Required fields are marked *

I accept that my given data and my IP address is sent to a server in the USA only for the purpose of spam prevention through the Akismet program.More information on Akismet and GDPR.