RESTful Web Services: HATEOAS

Welcome to the final part of this review of the Pluralsight course RESTful Web Services with Node.js and Express by Jonathan Mills.


Jonathan is a JavaScript and Node.js expert working mostly in the MEAN Stack with individuals and companies to help build their technical skills to cope with the constantly changing landscape of software development.

He is also an ASP.NET insider and an international speaker focusing on JavaScript both in the browser and on the server.

Node.js and Express gives us the ability to write lightweight, fast, scalable APIs quickly.

Also in this series:

Part 1 – What is REST?
Part 2 – Getting Data
Part 3 – Posting Data
Part 4 – Updating Data
Part 5 – Testing

In this course we have built out all of our HTTP verbs, and written unit and integration tests. The last remaining item is  HATEOAS: Hypermedia As The Engine Of Application State


The Problem Around Navigating APIs

We currently provide a hexadecimal id when we only want a single book. The technique that has been used so far is to copy the id retrieved for the complete book list results, and paste it into the URL.

Customers would not be able to intuitively use this API.

HATEOAS aims to self document your API with hypertext links.

Adding Hypermedia to Our API

In our bookController we forEach through each of our books.

Jonathan explains that we need to create a new book and copy the element over inside this loop. In here we add a new links object and this contains a child object called self.

self is the URL that we use to fetch the resource.

Now if we run the API when we see the full list of books we can just click a link to move to the singular book view. This is much easier to use.

Next we update bookRoutes.js with a get method for our singular book route. This includes links.FilterByThisGenre.

When we run it again we can click the FilterByThisGenre link to all of the books that have the same genre.

There’s a problem with the “Historical Fiction” genre because the space character needs to be URL encoded to %20, but that’s a simple fix.

And that concludes the course!



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s