When using ngResource/$resource, it is possible to implement custom (de)serialisation by specifying transformRequest/transformResponse. However these only control the request's body (data), so how can one manipulate the query parameters in a GET request?
Specifically, I would like to json-encode all the parameter values.
Simple case:
?user=123 is user with id 123
?user="123" is user with name 123
Complex case:
Passing objects/hashes in a GET request. For example using a mongo-like syntax to specify request criteria/projection. (Please note this question is not about mongo specifcally)
You can use a request interceptor for this:
$httpProvider.interceptors.push(function() {
return {
'request': function(config) {
//config.params contains query/request parameters
if (config.params){
//Do something here...
}
return config;
}
};
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With