Narrator: So what exactly is HATEOAS?
So HATEOAS is an acronym stands for
hypermedia as the engine of application state.
And what this means is that when calling REST API
and getting back a response, an entity,
then the entity already contains all the related resources,
or all the pointers to the resources
that you might be interested in.
So for example, if the API returns user entity
and this user has some orders,
then in order to get those orders
the client would not need to call a separate API for orders,
but the user entity will have pointers to those orders.
So using this pattern, the client should not have any
prior knowledge about other resources.
The only thing the client should know is the first API,
the route endpoint,
and after calling this endpoint
then all the other related resources
are already contained in the route entity.
So let's see an example of implementing HATEOAS.
So for our example, I would like to introduce you to Genie.
Genie is a software made by Netflix
and this is basically an open source distributed
job orchestration engine, so you can think
of it as a giant scheduler that schedules various jobs
and monitors them and makes sure that everything works fine.
Now for our example, it doesn't really matter
what Genie is doing,
but the interesting part for us is Genie's API.
So let's take a look at the REST API exposed by Genie.
So this is Genie's API
and as you can see we are currently looking
at an API that gets a job
which means this API when calling this API,
and you can see here is the endpoint,
and you can also see that this endpoint is structured
exactly as we discussed with the API, the version,
and the entity, then this API gets
the metadata about a specific job.
Now let's scroll down
and take a look at what is the response for this API.
So after asking for a specific job,
as you can see here this is the ID
of the job we want to retrieve,
then this the response, this is the status code,
and these are the various properties of the job
we can see when it was created,
when it was updated, what is it's version,
the name of the job, and so on.
And if we scroll down we will see this links section.
So as you can see, the links section contains, well, links
to other entities that might be relevant
if you want to use Genie.
So we have a link to self, which is the entity itself
and to the output and the request and execution and
more data and entities related to this specific job.
So for example, if I retrieved this job and now I want
to know it's status, here I don't need to look
into the documentation for an API returning status.
I can look at the entity itself, at the job entity,
and go to that status link which is right here
and simply access this API.
So this API is already constructed for me
for this specific job and it returns the status of this job.
Now if you scroll up a little in the documentation
then you can see that right here the documentation
mentions HATEOAS specifically.
So the HATEOAS is built into the API
and from Genie's point of view this is definitely
something that should be used.
So again in short, HATEOAS is a pattern
that returns all the related entity's links
in the route entity so that the client should not
have any prior knowledge about the endpoints
of related entities.