HATEOAS client with AngularJS HATEOAS client with AngularJS angularjs angularjs

HATEOAS client with AngularJS


Checkout angular-hateoas. ITs an AngularJS module for using $resource with a HATEOAS-enabled REST API.


You could write a Response Transformation that would inspect your returned object, check for links, and resolve them before returning the response. See the section "Transforming Requests and Responses" in the $http service documentation.

Something like this:

transformResponse: function(rawData) {  var json = JSON.parse( rawData );  forEach( json.content.links, function(link) {    // resolve link...  });  return json;}

Since the "resolve link" step is itself an $http call, sub-references would also be resolved. HOWEVER, since these are asynchronous, you would likely return a promise instead of the real value; I don't know if the transform function is allowed to do this.

As @charlietfl pointed out, however, please note that this will result in several HTTP calls to return a single entity. Even though I like the concept of HATEOAS, this will likely result in sluggishness if too many calls are made. I'd suggest that your server return the data, or some of it, directly, PLUS the link for details.


Based on your comment about wanting to work with data as against links on the client, I think Restangular would be a good fit.