Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 5, 2022 03:10 am GMT

WTF is HATEOAS?

Recently I have been diving into the world of Laravel. I took it upon myself to speed run this great (a little outdated) Udemy course on creating REST APIs Link and come across something new and interesting. HATEOAS.

Wikipedia defines it as (get ready); Hypermedia as the Engine of Application State is a constraint of the REST application architecture that distinguishes it from other network application architectures. With HATEOAS, a client interacts with a network application whose application servers provide information dynamically through hypermedia.

WHAT?!

So my friends let me break it down for you.

Basically, it is just a way to architect our API's so it is easier for us or the client of the API to navigate through it.

Let me give you an example. Below is a Laravel transformer I created (one way to change the attribute names of our data from whats in the DB to the client) with the links for that resource included.

Code for HATOAS

At the top we have the transformer transforming the attribute names and below this we have the links for our routes.

Rel is the name of the link and the href is the route of the resource. My code is just getting the route and inputting the ID into the route URL of this resource.

Now, what does this look like in the response?

API Response

As you can see, each of our items has a new section called links and this contains links to the other resources that are linked to this one.

This enables easier navigation through our API's, kind of like a website!

I hope this little tip improves you API's!

Footer:
I am currently living in Japan and looking for work (local or remote) so if you have anything, send it my way!

Check out my portfolio here link.
Check out my twitter here link.


Original Link: https://dev.to/russellcareyy/wtf-is-hateoas-1726

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To