-
-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing arrays in get params #49
Conversation
Any opinion on this one? |
I'm doing some research to determine if there is a standard. |
Cool, thanks. 👍 |
Any update on this? I’m currently using my fixed version directly from github. Would be nice to merge this in. :) |
According to my research Rails and PHP only support the bracket notation. |
I think that bracket notation is the correct implementation. It looks like rails, express, php, and java support it. My only hangup is if there should be an option for using one vs the other. This change won't be backward compatible for anyone depending on |
I could add an option so that people can enable it if the change breaks something. Although I’d say increasing the major version and adding a line to changelog should be sufficient. In case you’d add an option: how would you name and add the config parameter? axios({
disableGetBracketNotation: true
}); I think bracket notation should be the default, so the option should fall back to the old behavior. |
I've been thinking and it may be better instead of just using a boolean flag, allow specifying a function for how to handle params. This would accommodate any variety of patterns: There are a couple options for doing this.
|
Yep, passing a function sounds better. So would you move |
Yeah, that's basically what I'm thinking. The thing I'm debating is that there's a bit of other logic in Maybe |
Any decisions made on this? |
I'm using a Python backend and ran into this issue. An extensible |
Also hoping for a fix. An ajax library that incorrectly serializes an array is not good! FYI express's req.query also expects the |
For anyone hitting this, I made a wrapper around axios that is 100% untested and definitely only suits the bare minimum of my needs, but it addresses this issue. It assumes a function where you pass in params (query string params) as an object, and the method, and the url
|
Sorry for the delay on this. A little background on the current implementation. The original version of axios was meant to provide an API directly compatible with Angular's $http service. The way that axios is sending Array params is how Angular is doing it. In the time since, axios has diverged in several ways. I was initially pretty set on not breaking backwards compatibility, but after stewing on it, and seeing that most (all?) popular backends support [] for array params, I think it's best to just make a breaking change, and bump the version. |
@maxhoffmann I would like to merge this. Can you make a couple quick changes?
replace(/%5B/gi, '[').
replace(/%5D/gi, ']');
toEqual('/foo?foo[]=bar&foo[]=baz'); This will make the URLs look a bit nicer. Thanks! |
Sure, changes are done. Looking forward to remove my fork from our |
Fixing arrays in get params
Thanks for merging! When is the next release? |
bump, waiting on this too 👍 |
👍 |
any plans for bumping the version number? |
@maxhoffmann sorry for the long delay on this. I just released 0.6.0 which includes your PR. |
I had an issue sending arrays via GET params to a Rails server. In the current implementation the key in the params does not contain square brackets so that the server doesn’t know that it should handle the incoming params as an array. It only takes the last one.
There already is a test that checks for the implementation without square brackets. Is this defined as a standard somewhere? I researched on some sites and apparently PHP and Ruby’s Rack only support the square bracket notation. As
transformRequest
does only work fordata
and also not forGET
requests I can’t override this functionality via the axios API. It seems that this has to be handled internally.I’m proposing to change the current implementation so that square brackets are used for array params in GET requests. What do you think?