Search code examples
angularjsspringspring-data-resthateoas

Read response headers when using angular-spring-data-rest


I am unable to find a way to read the response headers when using SpringDataRestAdapter and $http. I can successfully read and process the response object, but I need to be able to store the ETag that is return in the HTTP Header.

I can't find any mention of HTTP Headers, anybody know how to get to them?

function getData(uri) {

  var deferred =  $http({
    method: 'Get',
    url: uri
  });

  return SpringDataRestAdapter.process(deferred).then(function (processedResponse) {

    return processedResponse;

  });

}

Solution

  • Theoretically you should be able to chain then to your $http GET call and use the result promise as an input to SpringDataRestAdapter. Something like this:

    function getData(uri) {
    
      var deferred =  $http({
        method: 'Get',
        url: uri
      }).then(function(response) {
         // save ETag from response.headers
         ...
    
         return response;
      });
    
      return SpringDataRestAdapter.process(deferred).then(function (processedResponse) {
    
        return processedResponse;
    
      });
    
    }
    

    BTW, you can also use a shorthand for $http call:

    $http.get(url).then(...)