Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST Client Implementation Embracing HATEOAS Constraint?

Tags:

rest

hateoas

Does anybody know of an implementation of a REST client that embraces the constraint of Hypermedia as the Engine of Application State (HATEOAS)?

The Sun Cloud API seems to be a good candidate, judging from the way it's documented and a statement by the author to the effect that Ruby, Java, and Python implementations were in the works. But so far I've found no trace of the code.

I'm looking for anything - even a partial implementation would be helpful.

like image 329
Rich Apodaca Avatar asked Jul 24 '09 22:07

Rich Apodaca


People also ask

Is HATEOAS mandatory for REST?

It never has been, it's a much higher level than that. But when you do need REST, and you do use REST, then HATEOAS is a necessity. It's part of the package and a key to what makes it work at all.

What is HATEOAS how do you implement HATEOAS for a resource?

To implement HATEOAS, we would need to include related resources in the response. Instead of Student we use a return type of EntityModel<Student> . EntityModel is a simple class wrapping a domain object and allows adding links to it. We create a new resource.

What is the point of HATEOAS?

Using HATEOAS allows an API to clearly define a control logic that is available at the client-side. This enables them to follow links embedded in the API resources instead of having them manipulate URLs. This decouples clients from the URL structure so that changes don't end up hurting integration.


1 Answers

The very first thing you should look at is the common web browser. It is the standard for a client that embraces HATEOAS (at least to some degree).

This is how Hypermedia works. It's so simple that it's almost painful:

  1. you point your browser to http://pigs-are-cool.org/
  2. the browser loads the HTML page, images, CSS and so on.
    • At this point, the application (your browsing experience) is at a specific URI.
    • The browser is showing the content of that URI
  3. you see a link in the application
  4. you click the link
  5. the browser follows the link
    • at this point, the application is at a different URI
    • The browser is showing the content of the new URI

Now for a short explanation of how the two terms relate to the web browsing experience:

  • Hypermedia = HTML pages with the embedded links
  • Application state = What you're seeing in the browser at any point in time.

So HATEOAS actually describes what happens in a web browser when you go from web page to web page:

HTML pages with embedded links drive what you see in the browser at any point in time

The term HATEOAS is just an abstraction of this browsing experience.

Other examples of RESTful client applications include:

  • RSS and Feed readers. They traverse links given to them by users
  • Most AtomPub blog clients. They need merely a URI to a services document, and from there they find out where to upload images and blog posts, search and so on.
  • Probably Google Gadgets (and similar), but they're merely browsers in a different skin.
  • Web crawlers are also RESTful clients, but they're a niche market.

Some characteristics of RESTful client software:

  • The client works with with any server, given that it is primed with some URI and the server responds with an expected result (e.g. for an atom blog client, an Atom services document).
  • The client knows nothing about how the server designs its URIs other than what it can find out at runtime
  • The client knows enough media types and link relations to understand what the server is saying (e.g. Atom or RSS)
  • The client uses embedded links to find other resources; some automatically (like <img src=) some manually (like <a href=).

Very often they are driven by a user, and can correctly be termed "user agents", except for, say GoogleBot.

like image 127
mogsie Avatar answered Nov 16 '22 04:11

mogsie