I have the following $resouce service:
$scope.scenesResource = $resource(scenesUrl + ':lang/:id', {
lang: '@lang',
id: '@id'
}, {
create: {
method: 'POST',
headers: {
Authorization: localStorage.tokenType + ' ' + localStorage.accessToken
},
transformResponse: function (data, headers) {
//This is never getting called
console.log(data);
console.log(headers);
}
}
};
Despite any security issues, such as reading the access token from local storage, or never expiring it, the create method works fine.
I mean, it makes a request with the correct Authorization header, and gets a 201 Created response from the server.
The problem is that, the server, instead of responding with the new resource's id in the response body or payload, it returns the Location header:
Location: /scenes/en-us/ODc1ZmYwNzUtZDA5MS00ZWJkLTgyODYtZWUzMGMyMDdhMmYx
I have a promise function on the create method:
newResource.$create().then(function (newScene) {
//Handle scene
});
As you can see, I need newScene to be filled with all the information that the server responded so I can handle it properly. But this information is in the Location header.
I am unable to read this header using the transformResponse method above in the example, because the method is never getting called.
How can I read my Location header using $resource?