-
Notifications
You must be signed in to change notification settings - Fork 27.5k
feat($http): support custom params serializers #11461
feat($http): support custom params serializers #11461
Conversation
I think non string version should be a factory function like interceptors. Otherwise looks good |
To clarify (I was on phone before): When defining $httpProvider.interceptors.push(function($q, dependency1, dependency2) {
return {
'request': function(config) {
// same as above
},
'response': function(response) {
// same as above
}
};
}); Currently in this PR, when you define a param serializer, you specify either the name of a service or the serializer itself. I am proposing that, to keep parity with the interceptor API, that you must provide a factory function if specifying inline. E.g. $httpProvider.defaults.paramSerializer = ['someHelperService', function(someHelperService) {
return function(params) {
};
}]); |
One other thing is whether these serializers should be |
According to jQuery.params doc, objects should be serialized this way $.param({
a: {
b: 1,
c: 2
},
d: [ 3, 4, { e: 5 } ]
});
// "a[b]=1&a[c]=2&d[]=3&d[]=4&d[2][e]=5" If you don't want to implement this crazy serialization, maybe |
@petebacondarwin thnx for the review. Few remarks:
@jmendiara didn't know that jQuery does it to objects :-) I think we can support those without too much pain.... |
7c87cc5
to
12f261e
Compare
@petebacondarwin added docs and made serializers public. IMO it is better to leave interactions with DI as-is. @jmendiara added test + code for handling first-level values as objects. One things I'm not sure about, though, is encoding of keys. Should the new suffixes be encoded as well? Please have another look at it and let me know if there are any other items that needs to be taken care of before getting this one in. |
$.param({a:{'bar/a':'value'}})
//"a%5Bbar%2Fa%5D=value"
decodeURIComponent($.param({a:{'bar/a':'value'}}))
// "a[bar/a]=value" so... yes 😃 |
@jmendiara yeh, this is what I was expecting... will push an update... |
var parts = []; | ||
forEachSorted(params, function(value, key) { | ||
if (value === null || isUndefined(value)) return; | ||
if (isArray(value) || isObject(value) && jQueryMode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cosmetic: Maybe be explicit here with comparison precedence to have better maintenance?
if (isArray(value) || (isObject(value) && jQueryMode)) {
Other than docs tweaks this looks good to me. Thanks @pkozlowski-opensource and @jmendiara |
Closes angular#3740 Closes angular#7429 Closes angular#9224
12f261e
to
292c757
Compare
@petebacondarwin @jmendiara I believe that I've addressed all your comments. Pushed a new commit if you want to have a final look - if I don't hear from you by the end of the day I'm going to land it as-is. Thank you guys so much for reviewing this one! |
LGTM |
@pkozlowski-opensource: Couldn't this also have closed #6039 ? Are there any plans to document this new params serialization thingy (because right now it is as underdocumentd as it gets :)) ? |
Oops and oops (first day back from easter holidays - still recovering) 😃 So, it is a different issue, but (if I am not mistaken) jQuery uses the same As far as documentation is concerned, it is indeed documented :)
|
@pkozlowski-opensource: I've created a gist with some |
@jmendiara gist is not the most effective in raising issues. Please open a separate ticket for each problem (with a reproduce scenario!). But before doing so, please check that an issue wan't open - https://github.com/angular/angular.js/issues?q=is%3Aopen+is%3Aissue+label%3A%22component%3A+%24http%22 - I'm pretty sure that there are issues already open for most of the items from your list (especially around caching) |
Closes angular#3740 Closes angular#7429 Closes angular#9224 Closes angular#11461
@pkozlowski-opensource |
@petebacondarwin I still need to add docs but if you could have a look at the impl / tests it would help us iterate faster on this one.