3

I'm trying to learn about REST and having problems with the concept of HATEOAS (Hypermedia As The Engine Of Application State). What is it for?

It seems to me the majority of commenters on the web think that HATEOAS should be used by a client to discover how to use a RESTful web service. And most seem to conclude that HATEOAS is not worth including in RESTful web services for one of two reasons:

1) HATEOAS only gives URLs but these are useless by themselves without knowing what methods can be used with each URL (eg HTTP GET, POST, PUT). Since the additional information must be passed to the client out of band (eg via documentation) then there is no point in using HATEOAS;

2) Similar to (1) but takes it a step further: The client can figure out what methods are applicable to a given URL by calling the HTTP OPTIONS method. However, the client still needs out of band information, to describe the format of the data it must pass for, say, POST or PUT methods. So we end up in the same place as (1) - HATEOAS isn't sufficient for a client to discover everything it needs to know, so why bother with it.

These arguments seem valid if HATEOAS is supposed to be used by a client to discover how to use a RESTful web service. However, is that what HATEOAS is for? From the few examples I've seen, it seems to me to be perfect for navigating through a web service - I've performed a certain action, now what are the valid actions I can perform next? That seems to me to gel with the "Application State" part of HATEOAS but very few articles I've read talk of it in terms of navigation, almost all are about discovery.

So, is HATEOAS about discovering how to use a RESTful web service or is it really about navigation?

  • "According to the Richardson Maturity Model, HATEOAS is considered the final level of REST. This means that each link is presumed to implement the standard REST verbs of GET, POST, PUT, and DELETE (or a subset). Thus providing the links as shown above gives the client [all] the information they need to navigate the service." -- https://spring.io/understanding/HATEOAS
  • – Robert Harvey Jan 15 '16 at 06:37
  • "A client does not need to understand every media type and communication mechanism offered by the server. The ability to understand new media types can be acquired at run-time through "code-on-demand" provided to the client by the server." -- https://en.wikipedia.org/wiki/HATEOAS, which also provides detailed examples of HATEOAS in action.
  • – Robert Harvey Jan 15 '16 at 06:41
  • These arguments seem valid if HATEOAS is supposed to be used by a client to discover how to use a RESTful web service. However, is that what HATEOAS is for? From the few examples I've seen, it seems to me to be perfect for navigating through a web service -- Isn't learning how to navigate through a web service part of the discovery process? – Robert Harvey Jan 15 '16 at 06:44
  • 4
  • 1
    @RobertHarvey: I found the spring article much the same as many of the examples I've seen, all about links and implying HATEOAS is just about navigation, without saying it explicitly. The Wikipedia article was confusing: The Details section was just about links, once again, but it also included the quote "A REST client needs no prior knowledge about how to interact with any particular application or server beyond a generic understanding of hypermedia", suggesting HATEOAS is about discovery in general, not just links. However, your link "What does HATEOAS offer..." was very illuminating. Thanks – Simon Elms Jan 16 '16 at 22:27
  • Is hateos an attempt to implement a wsdl via http – Ewan Jan 20 '16 at 09:32
  • @Ewan: It seems like it, to an extent (based on my very limited understanding). But it's more than that because it also involves state. ie This is where I'm at now, what valid actions can I perform from here? So it includes links that represent those further actions. eg If I create a resource then the server may return a link to that resouce so I can update it or delete it if I wish. – Simon Elms Jan 20 '16 at 21:16
  • At some stage rest questions boil down to 'is rest actualy any good?' I think HATEOAS is perhaps a couple of steps after that stage. If you write a client for a rest service. It doesnt need to discover stuff and if it did it wouldnt be able to cope with what it discovered except in a super general way. The inherent flaw in JSON and REST is that json is not strongly typed and http methods dont have the deep meanings REST advocates would lile them to – Ewan Jan 21 '16 at 22:02