Skip to content

Instantly share code, notes, and snippets.

@mgonto
Created April 30, 2013 05:10
Show Gist options
  • Save mgonto/5486697 to your computer and use it in GitHub Desktop.
Save mgonto/5486697 to your computer and use it in GitHub Desktop.
Restangular responseInterceptor
app.config(function(RestangularProvider) {
// First let's set listTypeIsArray to false, as we have the array wrapped in some other object.
RestangularProvider.setListTypeIsArray(false);
// Now let's configure the response extractor for each request
RestangularProvider.setResponseExtractor(function(response, operation, what, url) {
var newResponse;
// This is a get for a list
if (operation === "getList") {
// First the newResponse will be response.objects which is actually an array
newResponse = response.objects;
// Then we add to this array a special property containing the metadata for paging for example
newResponse.metadata = response.data.meta;
} else {
// If it's an element, then we just return the "regular" response as there's no object wrapping it
newResponse = response;
}
return newResponse;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment