HATEOAS — Hypermedia as the Engine of Application State is an important constraint of REST architecture as defined by Roy Fielding. To better understand the principle I’ve been discussing the topic with various REST enthusiasts. In this post I would like to provide an update on some of the learning points. There are arguably quite a few false claims of RESTful-ness (by API providers) while not following some of the basic tenets of REST. HATEOAS seems to be one of the main principles that is either misunderstood or not implemented in its true spirit.
Hypermedia and Application State
There are two important pieces here:
- What is Hypermedia?: Just as Hypertext documents contains links to other chunks of text, Hypermedia links to many media types including — text, images, audio, video, etc. WWW is a common example of Hypermedia.
- What is application state?: Not to be mistaken with the resource state. Application state is the state of the user’s application of computing to a given task. This is an important distinction, as Mark Baker explains in this InfoQ article:
“application state” refers to the state that determines “where” the user is in the process of completing a task. For example, when doing personal banking, is the user currently viewing account balances, filling in a bill payment form, or about to order new cheques? Those are each different application states. Some people mistakenly believe that “state” here refers to resource state, which would include, in this example, the balance of the accounts or the list of recent payments made. That isn’t the case.
HATEOAS achieves two very important aspects — protocol is not stateful, and loose coupling of client-server can be achieved as the server evolves describing new URIs.
Source of some confusion
Roy Fielding published a post in an effort to clarify what a true RESTful API is and how people are abusing the term. The last bullet point of the post says that ..
A REST API should be entered with no prior knowledge beyond the initial URI (bookmark) and set of standardized media types that are appropriate for the intended audience (i.e., expected to be understood by any client that might use the API). …
That along with some related discussions raised some interesting questions in my mind about how much prior knowledge that a client can have.
Ask an Expert
I have asked Subbu Allamaraju a couple of questions in this regard (Subbu is well known in this area, I learnt a lot from his blog posts and articles. He works at Yahoo developing standards, patterns and practices for HTTP web languages, and is extremely passionate about REST).
Question: How much information should the client know? If I strictly go by Fielding, it should only know the start page, and server should take care of the rest, driving the flow?
Subbu: That may be possible, provided the client knows all the link relations and media types. But there is no such constraint as having one staring URI. The idea is to keep representations contextual, but not necessarily to limit the number of prepublished URIs to one. When a representation is contextual, the client can decouple itself from server’s business rules.
In other words, what a client can do on a given resource depends on some business rules on the server. Instead of the client guessing that it can do certain action on a given resource, it can rely on the links contained in the representation. That is, by embedding application state and context into representations, servers can avoid leaking business rules to clients. That is the main benefit of HATEOAS for client-server apps.
[Next question could sound a bit extreme to some folks, but I read the idea earlier and so wanted find Subbu's take on that.]
Question: Is it practical to say that the client shouldn’t know anything including the fields that are being worked on (say username and password fields of the form) and shouldn’t know about what page it is posting to, say “/login”.
Subbu: This may be not practical and can be prohibitively expensive.
Media types, link relations and things like microformats can help to a certain extent. In the case of XHTML representations containing well-known microformats, you may be able to minimize the amount of information a client will need to know to intelligently interact with a RESTful server. Even on the web, given a perfectly described XHTML, try replacing a human with a perl program. How far can that perl script go? Can it pass the Turing test?
If automation and self-discovery is the goal, of course, it may be worth trying. But I doubt if every application needs that capability.
[Subbu's Describing RESTful applications is an excellent article that explains HATEOAS and more. Highly recommended]
Next Steps
Along the lines I will be closely following Solomon Duskis’ thought process to see what his experiments result in. Solomon and I had some good conversations, and his posts helped provoke some thought.
I guess the best way to understand this is by reviewing a good example. I’ve asked the following question on Twitter
If asked about an example of truly RESTful API, which (publicly available) API do you point to? Interested: no-state-on-server, HATEOAS.
.. for which I got a couple of responses — Amazon S3 and NetFlix. Did some research and found some good reviews on NetFlix API, so will explore that further ..

Follow on Twitter