New config param: arrayFormat ?
See original GitHub issueSummary
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
https://stackoverflow.com/questions/3061273/send-an-array-with-an-http-get
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.
https://github.com/axios/axios/blob/master/lib/helpers/buildURL.js#L43
Context
- axios version: 0.18.0
- Environment: chrome 65
Issue Analytics
- State:
- Created 5 years ago
- Reactions:18
- Comments:11 (1 by maintainers)
Top Results From Across the Web
How to correctly use axios params with arrays - Stack Overflow
So I assigned the paramsSerializer of axios like this: config.paramsSerializer = p => { return qs.stringify(p, {arrayFormat: 'brackets'}) }.
Read more >Request Config | Axios Docs
These are the available config options for making requests. ... It can be convenient to set `baseURL` for an instance of axios to...
Read more >Describing Parameters - Swagger
To learn about the latest version, visit OpenAPI 3 pages. ... collectionFormat specifies the array format (a single parameter with multiple parameter or ......
Read more >Axios Cheat Sheet - Kapeli - Dash for macOS
It can be convenient to set `baseURL` for an instance of axios to pass ... function(params) { return Qs.stringify(params, {arrayFormat: 'brackets'}) } ...
Read more >Configuring tasks - Grunt: The JavaScript Task Runner
renameTask, Grunt will look for a property with the new task name in the config object. Options. Inside a task configuration, an options...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:
Using the qs library:
If there is no standard/RFC that defines this, why was it decided that
[]
should be used? I understand a customparamsSerializer
can be implemented, but the current implementation shouldn’t be opinionated.I used this solution, unfortunately it requires an additional package for something that perhaps can be fixed with a simple toggle config. https://github.com/axios/axios/issues/559#issuecomment-264689998