Created
April 30, 2013 05:10
-
-
Save mgonto/5486697 to your computer and use it in GitHub Desktop.
Restangular responseInterceptor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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