-
-
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
New config param: arrayFormat ? #1443
Comments
FWIW, I needed to swap out the default qs serializer in here for |
On node 10.6, I just tried using the built-in https://nodejs.org/api/querystring.html#querystring_querystring_stringify_obj_sep_eq_options |
If there is no standard/RFC that defines this, why was it decided that I used this solution, unfortunately it requires an additional package for something that perhaps can be fixed with a simple toggle config. |
up |
Also would like to see a better solution for this. |
Really understand that users want everything out-of-box. But axios has its own design principle, which means simple and focused. Hope someone can list where those two formats come from, and let's choose the more standard one. |
the better solution is to use JSON arrays with |
On this I don't think this should be implement as mentioned previously if you'd like to use another format, you can set a custom paramsSerializer as follows: axios.defaults.paramsSerializer: function(params) {
// return a query string
} Using the qs library: axios.defaults.paramsSerializer: function(params) {
return qs.stringify(params, { indices: false }); // param=value1¶m=value2
} |
I have a problem with the by @jasonsaayman mentioned approach...
Not sure yet how to solve this. Anyone? Update: Nevermind. While debugging I figured out the actual issue was something completely different ^^ |
I'm not sure I fully agree. There is nothing in the specification that says that these parameters should be suffixed with brackets (neither is there anything that says that it shouldn't), which makes this very opinionated (as mentioned previously). Fixing this by adding the I could rely on the native Node.js
I could also replicate the entire function that Axios has by default, but that also feels like a very inconvenient way of handling this. Could you consider re-opening this issue? 😃 |
I already had tried something like this: #1565 But same response: use qs. |
For those like me that are just now stumbling upon this thread, the bracketless format can now be configured:
|
need to check if this in the docs @DavidJDallas |
closing due to being very stale, if this is still relevant please open a new issue |
Summary
Now when i send an array in GET request
axios.get('/url', { id: [1, 2, 3] })
I receive this path:
/url?id[]=1&id[]=2id[]=3
and it's not configurable.But some target servers (with strong typed languages) wants another format (without braces after param name):
/url?id=1&id=2id=3
And now I have to use
paramsSerializer
(right this case is mentioned in README), and even to use another package (Qs).But I found in
buildURL
function than brackets is added forcibly, and it's quite easy to add options param to handle it.Context
The text was updated successfully, but these errors were encountered: