I hear this line about how a proper REST system does not require a consumer to have any a priori knowledge of the system to consume it. How is this possible without a standardized method of describing services (in the spirit of WSDL)? Why is this a design goal for a system anyway? I work on mobile, and if I'm going to invest effort in writing a client for a service, you can bet I'm going to have a ton of a priori knowledge about it.
1. Hypermedia - you have no a priori knowledge of the uri structure
because each resource you request contains links to state transitions
that are identified by name. Such as an order has a "cancel" state.
That cancel state may or may not be available based on other business
rules on the order (such as orders can't be canceled after they are
shipped).
Providing state transitions via hypermedia allows the server to change
uri schemes without updating clients. As long as the client checks for
the existence of the cancel state and then calls the link specified in
the href, the server and the client can evolve independently. This is
especially important for a service provider for mobile where you don't
have control over your customers mobile apps.
2. Media Types - the misconception about documentation is that NO
documents are allowed. This is definitely not true. In fact, documents
for media types are encouraged. Media types are equivalent to "HTML"
they say what a resource document may contain but not whether it will
contain it or what data is in it. For example in the order scenario
above, the document for the order media type would say that a cancel
state transition is possible but not guaranteed to be there.
Its fair to say also that without hypermedia, you cannot have a rest
api without uri documentation, its just not possible.
Jason
--
Jason Sirota
ja...@sirotamail.com
http://twitter.com/jasonsirota
http://jasonsirota.com/
Providing state transitions via hypermedia allows the server to change
uri schemes without updating clients.
On Thu, Sep 1, 2011 at 11:46 PM, Jason Sirota <ja...@sirotamail.com> wrote:Providing state transitions via hypermedia allows the server to change
uri schemes without updating clients.Let me correct one thing here, the server can change uri schemes and state transitions as business rules evolves. Thus if your business decides that it wants to allow cancellations after items are shipped it can do so without informing clients of a documentation change.
The alternative is to have a GET order/1/cancel uri or if you're using http verbs a DELETE /order/1 action and the server returns an error if cancellation is not allowed. An acceptable alternative but could be jarring if your clients are both not expecting state changes (because you didn't tell them about it ahead of time) and did not handle the error. With hypermedia, the client application is designed to not expect cancel to be there and therefore can account for situations where cancel is allowed and not allowed.Ah, so perhaps "a priori knowledge" really only refers to URI structure. I'm totally cool with URI links to child resources and state transitions.
This seems a little pie-in-the-sky if you ask me. If I was building an iPhone app that implemented a front-end for this example service, I bet that there are non-trivial UI changes that would need to be made if the business rules changed as you described here. So again, I'm questioning why this sort of thing is a design goal.
Category 2: Constraining functionality over time (Removing the cancel function)
...This one includes saying at one point in time a particular function is available but later you want to remove that functionality. If the client obeys hypermedia, then that @rel will no longer be available. I still believe this will break client functionality, in most clients executing a "rel" means something, so a client has to be very clever to adjust functionality (remove the cancel button) based on whether a @rel is available or not. This requires just as much diligence in obeying hypermedia constrants on the consumer as well as the producer of a service. Therefore, the level-of-effort shift is negated.
This also leads to my next question…On Fri, Sep 2, 2011 at 8:36 AM, Kevin Swiber <ksw...@gmail.com> wrote:The alternative is to have a GET order/1/cancel uri or if you're using http verbs a DELETE /order/1 action and the server returns an error if cancellation is not allowed. An acceptable alternative but could be jarring if your clients are both not expecting state changes (because you didn't tell them about it ahead of time) and did not handle the error. With hypermedia, the client application is designed to not expect cancel to be there and therefore can account for situations where cancel is allowed and not allowed.Ah, so perhaps "a priori knowledge" really only refers to URI structure. I'm totally cool with URI links to child resources and state transitions.What are state transitions? Does that refer to resources like /orders/1/cancel? Why would you do that rather than DELETE /orders/1?
On Thu, Sep 1, 2011 at 11:46 PM, Jason Sirota <ja...@sirotamail.com> wrote:Providing state transitions via hypermedia allows the server to change
uri schemes without updating clients.Let me correct one thing here, the server can change uri schemes and state transitions as business rules evolves. Thus if your business decides that it wants to allow cancellations after items are shipped it can do so without informing clients of a documentation change.This seems a little pie-in-the-sky if you ask me. If I was building an iPhone app that implemented a front-end for this example service, I bet that there are non-trivial UI changes that would need to be made if the business rules changed as you described here. So again, I'm questioning why this sort of thing is a design goal.
What are state transitions? Does that refer to resources like /orders/1/cancel? Why would you do that rather than DELETE /orders/1?
I am sorry I'm late to this discussion. First off, if you all haven't
discovered these two posts yet, I highly recommend them. Steve Klabnik
says he may write a book on REST, I certainly hope he does.
http://blog.steveklabnik.com/2011/07/03/nobody-understands-rest-or-http.html
and then
http://blog.steveklabnik.com/2011/08/07/some-people-understand-rest-and-http.html
As I mentioned before, one goal for REST is the enablement of
intelligent clients. The clients don't exist because there aren't just
tons of RESTful services for us to interact with today. If I had a
javascript/iOS/Silverlight(ugh) library that actively disabled/removed
components of the UI based on what the server makes available in terms
of interactions, I'd use the hell out of that ability.
It's not saving you code or effort today because our tools haven't
matured just yet. I think we've gotten to a point where it's certainly
possible and that's just one great reason this Google group is so
valuable : )
On Mon, Sep 5, 2011 at 2:32 PM, Alex Robson <asro...@gmail.com> wrote:As I mentioned before, one goal for REST is the enablement of
intelligent clients. The clients don't exist because there aren't just
tons of RESTful services for us to interact with today. If I had a
javascript/iOS/Silverlight(ugh) library that actively disabled/removed
components of the UI based on what the server makes available in terms
of interactions, I'd use the hell out of that ability.
Adding to that and echoing previous statements, I still want my clients responsible for user experience. Therefore, I need upfront knowledge of the possible use cases. In JavaScript, I'd likely assign callbacks that enable/disable components based on the existence/absence of known possible links. I'd be hesitant to dynamically build UI elements based on any link found in the hypermedia response.
I guess what I'm saying is that, in my view, none of this stuff obviates the need for a versioning system. It just seems to recommend some nice ways to implement common classes of functionality in a way that respects HTTP—like how DELETE /widgets/1 is just kind of more elegant than a SOAP call to DeleteWidgetByID().
Wow. There are a whole lot of issues in this thread, maybe I'll start with the original topic.
Jason is correct in that most of the time when people are talking about not having prior knowledge of a REST service they are talking about URI structure. To give a real practical example of how this is possible, take a look at http://amundsen.com/hypermedia/profiles/. During the hackday at RESTfest we took this document and a number of us built clients and servers based purely on this spec and then were able to successful demonstrate interoperability between clients and servers. Not only does that spec not define any URIs it, doesn't even define what resources need to exist. Now, the experiment showed that the spec was slightly underspecified, but only because of missing link relations.