I got the Restful web services book (Leonard Richardson and Sam Ruby) from my University Library. Actually I was the one that asked for it to be bought, as I’m teaching Web Application Servers, and I thought it a useful twist on the materials I have been using in the past.
I found an interesting comparison: I usually teach, for a different matter, Object Oriented Analysis and Design, the classic Liskov & Gutka classification on Abstract Types and Operations (see for instance this PDF, funny that the first page for the seach was all academic papers in PDF). While looking to how the use of REST methods fits with the classification, I found something obvious and something that was not so obvious for me:
new operator in java or C# that can’t avoid creating a new object. More on this later.new would, but rather like string concatenation or a factory method would.This last kind of operation, Producers, is common in OO languages for a number of reasons: one of the big downsides of java and other languages is that new has to return a new object, which prohibits interning of objects, the use of the flyweight pattern and a number of useful techniques. Also, throwing exceptions in initializers is considered rude, and a pain to deal with, and this is the only solution for a new that violates a representation invariant. So producers in the guise of factory methods end up getting used a lot. The alternative, no argument constructors plus bean-like setters, is only useful where the representation invariant is trivial. Also, creation of a related resource, like a sublist of a list or, say, a comment on an entry, is the typical producer field. This is where POST rules.
In REST the problems for constructors is a bit different: using PUT to create a resource is only possible when the client can dictate the URI to the Service, as the URI is a really important part of the representation invariant in REST :) I’m not sure how the use of PUT+redirect for constructing/producing objects is considered by the REST world at large, but I consider it tricky at best. I wonder too how this post as a whole fits with Joe Gregorio practices.
The Liskov & Gutka PDF link returns a 404 :-(
This was an instance of Google brokenness, as PDFs don’t offer a place to copy the URL from, and I messed it when removing the encoding from google’s result page.
The one I post is from the 6170 course at MIT, it can be found at opencourseware.
On unrelated news, I think I have the POST and PUT use for Mutators wrong. I need to check it and edit, when I finish the September exams rush here.