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
0:03 or as it is known— HATEOAS
0:07 is enabled by default on the framework.
0:11 So each get response includes a links section,
0:14 links provide details on their relation
0:18 relative to the resource being accessed and a title.
0:21 Relations and titles can then be used by clients
0:26 to dynamically update their UI
0:28 or to navigate the API without knowing its structure beforehand.
0:34 Hyper media as the engine of application state is a nice feature
0:37 it is included in the Rest principles and by default,
0:41 the Eve framework supports it,
0:43 but to be honest, I've not seen so many clients make use of this feature
0:48 and also many Rest services are not providing it.
0:52 So you have the option to turn it off if you want to
0:55 let's go and first look at the typical output you get from a get request.
1:01 Let's close the items array and here it is our links section,
1:06 we don't want these, let's see how we turn it off.
1:11 By now you probably already imagine what's going to happen.
1:16 I've just set HATEOAS to false. Save, relaunch.
1:26 And send a request again
1:28 we're still getting the items array, the meta tag is still there
1:33 but there's no links section
1:36 so we have disabled the feature completely,
1:40 let's go to a single document endpoint,
1:43 no links section here neither.
1:47 Now, if we want the feature on
1:50 but we want to change the key used in the Json for this feature,
1:56 we can do that very easily
1:58 we just need go back, enable the feature
2:02 then set links equal to whatever value we want to use as the key for the feature.
2:08 So here we're using links, but without the underscore
2:14 let's restart the server, and see what happens
2:18 bam, feature is back on but this time
2:20 we have customized the key used for the feature.
2:24 We can also check the people endpoint,
2:28 links is there without the underscore and the feature is back.
2:33 It is worth noting that when you disable the feature,
2:37 you're also losing the pagination feature because as you know,
2:41 pagination links are included within the links section.
2:44 This is probably worth considering
2:46 you get a nice performance boost because you aren't doing any pagination.
2:51 You don't have any links section,
2:53 but you are also losing some valuable information for your clients.
2:58 Finally, keep in mind that you can also
3:03 switch the feature on and off at a local level,
3:05 so here we have the feature on globally,
3:08 but we can go to the people endpoint for example,
3:11 and set it to off, if we don't want it at this endpoint.