Eve: Building RESTful APIs with MongoDB and Flask Transcripts
Chapter: Fine-tuning your REST service
Lecture: HATEOAS
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Hypermedia as the engine of application state or as it is known— HATEOAS is enabled by default on the framework.
0:12
So each get response includes a links section, links provide details on their relation relative to the resource being accessed and a title.
0:22
Relations and titles can then be used by clients to dynamically update their UI or to navigate the API without knowing its structure beforehand.
0:35
Hyper media as the engine of application state is a nice feature it is included in the Rest principles and by default, the Eve framework supports it,
0:44
but to be honest, I've not seen so many clients make use of this feature and also many Rest services are not providing it.
0:53
So you have the option to turn it off if you want to let's go and first look at the typical output you get from a get request.
1:02
Let's close the items array and here it is our links section, we don't want these, let's see how we turn it off.
1:12
By now you probably already imagine what's going to happen. I've just set HATEOAS to false. Save, relaunch. And send a request again
1:29
we're still getting the items array, the meta tag is still there but there's no links section so we have disabled the feature completely,
1:41
let's go to a single document endpoint, no links section here neither. Now, if we want the feature on
1:51
but we want to change the key used in the Json for this feature, we can do that very easily we just need go back, enable the feature
2:03
then set links equal to whatever value we want to use as the key for the feature. So here we're using links, but without the underscore
2:15
let's restart the server, and see what happens bam, feature is back on but this time we have customized the key used for the feature.
2:25
We can also check the people endpoint, links is there without the underscore and the feature is back.
2:34
It is worth noting that when you disable the feature, you're also losing the pagination feature because as you know,
2:42
pagination links are included within the links section. This is probably worth considering
2:47
you get a nice performance boost because you aren't doing any pagination. You don't have any links section,
2:54
but you are also losing some valuable information for your clients. Finally, keep in mind that you can also
3:04
switch the feature on and off at a local level, so here we have the feature on globally, but we can go to the people endpoint for example,
3:12
and set it to off, if we don't want it at this endpoint.