Skip to content

Instantly share code, notes, and snippets.

@devmop
Created April 10, 2015 08:35
Show Gist options
  • Save devmop/64c9ca0c7e6f4197655a to your computer and use it in GitHub Desktop.
Save devmop/64c9ca0c7e6f4197655a to your computer and use it in GitHub Desktop.
HATEOAS

The general gist is to have a bunch of links with "method" names describing the operations you can perform on it. Supposedly this gets you the advantage of not hardcoding urls into your clients.

Example from Wikipedia:

    <account>
       <account_number>12345</account_number>
       <balance currency="usd">100.00</balance>
       <link rel="deposit" href="/account/12345/deposit" />
       <link rel="withdraw" href="/account/12345/withdraw" /> 
       <link rel="transfer" href="/account/12345/transfer" />
       <link rel="close" href="/account/12345/close" />
     </account>```

I've spent a long time thinking this is an utter waste of an abstraction. Clients still have functionality hardcoded. They have to. They need to be able to understand what they're calling and the data to pass in.

Apparently all you'll have gained is the ability to move the urls around.
Then I realised you can CHANGE the urls. You can pass context data from the current request into a subsequent one without the client needing to understand what the context was. They never have to learn it.

An example - search results. A page of results where each link is just to the relevant document.
One day you decide that it'd be nice to know which links users were clicking. The first thought would probably be to leave all the links alone and orchestrate the client. With HATEOAS you just embed `resultno=5` somewhere in the link and record the fact it was followed server side later. No client changes required at all.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment