HATEOAS in few words: In the data you output, refer to other resources using URIs, not IDs.
As all the short definitions, the definition I just gave is wrong on many levels, but it should make you understand what the crux of HATEOAS is.
Now, for a bit longer explaination.
The HATEOAS principle says that the state of your application should advance through hypertext links. Think of you browsing around the internet. First you have to type an address in the address bar. From that point on, your navigation advances pretty much only thanks to clicks on links: you click on a link and you end up on another page. Another click and here appears another page. How was the browser able to move you from the first page to the second to the third? It used the URLs encoded in <a>
elements.
Similarly if your REST applications generates this result
<accomodation>
<hotel info="http://example/hotel/0928374" price="200"/>
<guest-house info="http://example/guest-h/7082" price="87"/>
</accomodation>
then the receiving application will not have to access any external sources of knowledge to know that the first hotel is available at http://example/hotel/0928374
and the second one at http://example/guest-h/7082
.
On the other hand, if your application generates responses with IDs like
<accomodation>
<hotel id="0928374" price="200"/>
<guest-house id="7082" price="87"/>
</accomodation>
the receiving application will have to know in advance how IDs must be composed with prefixes to get the URI at which the information for each accommodation is available (for example "add http://example/
to every request, then add hotel
for hotels and guest-h
for guest houses"). You can see that this mechanism is similar to what happens in many DB applications but is different from how browsers work.
It is important to follow the HATEOAS principle because it allows applications to grow without drastic changes to the receiving applications. Suppose you want to change your URIs from http://example.com/hotel/0928374
to https://reviews.example.com/accommodation/0928374
. If you followed HATEOAS is would be a simple change: modify the returned values and that it is: receiving applications will continue to work without any modification. If instead you had separate documentation for how to construct URI, you will have to contact all the application developers and ask them to notice that the documentation has been updated and they should change their code to reflect the changes.
Disclaimer: this is a quick answer that just scratches the surface of the problem. But if you get this you got 80% of the HATEOAS principle.
Hypermedia As The Engine Of Application State
– Enisle