Is it possible to consume a hateoas type of restful webservice via (a) javascript (framework - e.g. angularjs)? I imagine that the client needs to implement quite a lot of logic to reach the actual endpoint. Any feedback would be very much appreciated. Thanks!
-
2What's wrong with SO these days? Would love to know why someone voted to close this question ... – cs0815 Jun 23 '13 at 10:18
-
1This is related http://stackoverflow.com/questions/9204110/restful-api-runtime-discoverability-hateoas-client-design – cs0815 Jun 24 '13 at 20:16
-
That is why I do not believe in HATEOAS. My answer was more suited as a comments so deleted the answer. – Aliostad Jun 25 '13 at 11:42
-
It's kind of an answer, if you as an export reckon, that it is currently impossible to consume hateoas restful web services. Maybe I misunderstood you. My current impression is that hateoas service are very appealing but there are currently no practical solutions in place to consume them via JavaScript. I guess that;s what Darrel tries to say too but I am reluctant to accept that as an answer yet. – cs0815 Jun 26 '13 at 12:03
-
It is not impossible. For me, it is pointless since - long story short - I do not believe in HATEOAS. But you should be able to do that, just have to code it yourself. It depends on how you expose links, you can use Collection+json or HAL or use RFC 5988. – Aliostad Jun 26 '13 at 12:21
2 Answers
At least part of the issue here is that your API needs to return a media type that supports structured linking (which the usual "REST" API defaults application/json
and application/xml
do not). To get this support, checkout the HAL or JSONAPI projects.
With a structured linking definition, it becomes much easier to consume - HAL has several libraries to work with it, including a javascript library:
https://github.com/mikekelly/backbone.hal
For an interesting client, checkout the HAL Talk demo.

- 3,369
- 2
- 28
- 32
Yes it is possible. Javascript is just another user-agent.
Yes there is work to do. No I am not aware of any frameworks to do this for you. I have written tooling for supporting hypermedia driving applications on the desktop and I don't consider it a significant amount of work to produce the infrastructure to support hypermedia based applications.
The challenge is less about the tooling and more about the fact that it is a very different approach to building applications. It takes some getting used to.
On a related note there is some ongoing work in the Browser/JS space that will make doing hypermedia driven applications on the client much easier. See NavigatingController. Currently a JS user-agent can only manage javascript links. With NavigatingController it becomes possible to intercept HTML links also, making JS driven applications much more seamless in the browser.

- 139,164
- 32
- 194
- 243
-
1My understanding is that there is only one endpoint exposed by a hateoas web service. To reach a specific endpoint the client has to talk to the web service and navigate via the uris it receives to this specific endpoint. IMHO this requires some 'involved' logic on the client's side. I would like to see a JS implementation to achieve this (ideally using a framework like angular.js). Hope this makes sense. – cs0815 Jun 23 '13 at 10:16