I'm trying to remove custom parameters from the following HTTP request on my REST API:
I want to turn http://localhost:3000/users?_page=1&_perPage=30&_sortDir=DESC&_sortField=id
into http://localhost:3000/users
I am using ng-admin, which is an AngularJS admin panel, they provide a page on changing query parameters here: https://github.com/marmelab/ng-admin/blob/master/doc/API-mapping.md
I have used some of their code and tried to use the following code to implement what I'm trying to do but it won't work.
myApp.config(['RestangularProvider', function(RestangularProvider) {
RestangularProvider.addFullRequestInterceptor(function(element, operation, what, url, headers, params, httpConfig) {
if (operation == 'getList' && what == 'entityName') {
delete params._page;
delete params._perPage;
delete params._sortField;
delete params._sortDir;
}
console.log({ params: params });
});
}]);
Finally, how can I check the actual HTTP request that is sent through once the interceptors have been utilised, chrome developer tools seems to only display the original request with all parameters even though I've implemented the above methods. I think this is because the interceptor works after the browser implements the request.
You should return whole request from interceptor otherwise there won't be any changes on request. It is written at documents.
addFullRequestInterceptor
at the last lines it said If a property isn't returned, the one sent is used. so if you send changed properties in an object then you should be fine...