HATEOAS RESTful service

HATEOAS stands for Hypermedia as the Engine of Application State. It’s a concept I encountered about 5 years ago, in an after work technical talk that was held in the old ThoughtWorks London office near Holborn.

HATEOAS is one of REST application architecture constraints that a client should interacts with a network application entirely through hypermedia provided dynamically by application servers.

cf). REST has the following 4 constraints.

  • Identification of Resource (typically by using a URI)
  • Manipulation of Resources through Representation
  • Self-descriptive message
  • Hypermedia as the engine of the Application STate

This an example of HATEOAS-based response.

{
    "name": "Mad Max",
    "links": [ {
        "rel": "self",
        "href": "http://localhost:8080/customer/1"
    } ]
}

A REST client needs no prior knowledge about how to interact with any particular application or server beyond a generic understanding of hypermedia. By contrast, in a service-oriented architecture (SOA), clients and servers interact through a fixed interface shared through documentation or an interface description language(IDL).

  • rel means relationship. In this case, it’s a self-referencing hyperlink.
  • href is a complete URL that uniquely defines the resource.

Although the example shown is in JSON, XML is also a standard response format. HATEOAS doesn’t impose the requirement of either format. The hypermedia links are the focus.

Let’s look at more complex relationships. (from Spring Data Book)

{
    "content": [ {
        "price": 499.00,
        "description": "Apple tablet device",
        "name": "iPad",
        "links": [ {
            "rel": "self",
            "href": "http://localhost:8080/product/1"
        } ],
        "attributes": {
            "connector": "socket"
        }
    }, {
        "price": 49.00,
        "description": "Dock for iPhone/iPad",
        "name": "Dock",
        "links": [ {
            "rel": "self",
            "href": "http://localhost:8080/product/3"
        } ],
        "attributes": {
            "connector": "plug"
        }
    } ],
    "links": [ {
        "rel": "product.search",
        "href": "http://localhost:8080/product/search"
    } ]
}   

Richardson Maturity Model states that HATEOAS is Level 3, the final level of REST

HATEOAS RESTful service

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s