|Project:||RESTful Web Services|
|Issue tags:||GSoC 2012|
I'm working on RestWS integration for the Backbone module (#1463024: Build RestWS Flavor), and have run into an issue regarding opposite uses of PUT and POST in Backbone.js's save() method as compared to the RestWS module's behavior, as defined in the README.txt.
While RestWS uses
HTTP PUT /<entity type name> for create and
HTTP POST /<entity type name>/<entity id>.<format> for update, Backbone uses
HTTP POST /<entity type name> for create (though the create URL can be changed...the REST verb is harder modify, though) and
HTTP PUT /<entity type name>/<entity id>.<format> for update.
I think there is considerable reason to believe that Backbone's implementation is the "correct" one with regard to the HTTP 1.1 standard and the intended use, though there is some variation in opinion that could warrant a flexible interpretation (perhaps an admin setting to switch?)
The fundamental difference between the POST and PUT requests is reflected in the different meaning of the Request-URI. The URI in a POST request identifies the resource that will handle the enclosed entity. That resource might be a data-accepting process, a gateway to some other protocol, or a separate entity that accepts annotations. In contrast, the URI in a PUT request identifies the entity enclosed with the request -- the user agent knows what URI is intended and the server MUST NOT attempt to apply the request to some other resource.
By this definition the POST URI should not include the entity ID, as it should refer to the entity type handler or other gateway, while the PUT URI can (must?) include the ID.
As this blog post discusses, PUT and POST are not defined in terms of CRUD operations, and there are understandable interpretations in which either could be used for create or update, but only if two successive calls to the PUT create would result in the same object, as PUT is defined in terms of its idempotence. Because subsequent calls to create a new node will result in nodes with different nid's, however, our PUT / is not idempotent.
I should note that while I have some experience with REST development and JSON REST frameworks, I cannot consider myself an expert. Still, I think these documents make a pretty strong case for POST for create and PUT for update in RestWS's case.
I am also very excited about the potential of using RestWS's entity-based approach with Backbone. What is the best way to resolve this issue?
Thanks for everything,