I've been attempting to perform a Restangular GET with multiple query parameters (for simple pagination) and it doesn't seem possible--at least with what I'm trying to do. Here's what I'm attempting to do:
Restangular.all('elevation').get({ pageParam: page, pageSizeParam: pageSize }).then(function(data) {
console.log(data);
});
WIth the expected response looking something like:
{ totalRecords: 233, elevations: {...} }
This does not work and results in the following:
GET http://localhost:24287/elevation/[object%20Object] 404 (Not Found)
I also attempting utilizing customGET as well which results in the same problem as above.
The only way I'm actually able to pass multiple query parameters is by using getList. Unfortunately when utilizing the getList unsurprisingly the following error is thrown:
Error: Response for getList SHOULD be an array and not an object or something else
To resolve this issue, the Restangular documentation states in the My response is actually wrapped with some metadata. How do I get the data in that case? section that I need to use addResponseInterceptor which I've done like so:
RestangularProvider.addResponseInterceptor(function(data, operation, what, url, response, deferred) {
var newResponse = [];
if(response.data.totalRecords !== undefined) {
newResponse.elevationData= {};
newResponse.elevationData.totalRecords = response.data.totalRecords;
newResponse.elevationData.elevations = response.data.elevations;
}
return newResponse;
});
After jumping through hoops this convoluted solution does in fact work. Is there not an easier way to simply call Restangular's get with multiple query parameters and get an object returned?
At this point, it would be a magnitude easier to take Restangular out of the question and simply use the $http service like so:
$http.get('http://localhost:24287/elevation?page=' + page + '&pageSize=' + pageSize).then(function(result) {
console.log(result.data.totalRecords);
console.log(result.data.elevations);
});
Though I really want to figure out a better way to do this with Restangular.
Any ideas would be greatly appreciated! Thanks!