XML.com: XML From the Inside Out

XML.comWebServices.XML.comO'Reilly Networkoreilly.com
  Articles | Weblogs | Newsletter | Safari Bookshelf
advertisement

Article:
 Telnet and REST Web Services?
Subject: PUT / POST and CREATE/UPDATE
Date: 2004-12-16 04:15:08
From: domfox

There isn't a direct mapping between PUT/CREATE and POST/UPDATE.


The real difference between PUT and POST is that PUT is idempotent (doing it once, then doing it again, has the same result as just doing it once) and POST is not (doing it once, then doing it again, may have a different result to just doing it once).


Here is a common scenario in which POST would be used for CREATE, and PUT for update.


The client POSTs a description of a resource to the server, which creates a resource based on that description and responds with a 201 (created) status code and a Location header pointing to the new resource.


The client then uses GET to retrieve a representation of this resource, and PUT to update it by sending a representation of the modified resource back to the same URL.


Alternatively, we could use PUT all the time: the client creates a resource, and PUTs a representation of it to the URL of its choice on the server, then uses GET and PUT to update that representation.


POST would then be used if we were doing something like sending a comment to be added to the foot of a page - it instructs the server to mutate the resource itself, by appending the comment, and might append the comment twice if it were sent twice.


No Previous Message Previous Message   Next Message Next Message

Sponsored By:


Contact Us | Our Mission | Privacy Policy | Advertise With Us | | Submissions Guidelines
Copyright © 2008 O'Reilly Media, Inc. | (707) 827-7000 / (800) 998-9938