question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New config param: arrayFormat ?

See original GitHub 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

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:closed
  • Created 5 years ago
  • Reactions:18
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
jasonsaaymancommented, May 27, 2020

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&param=value2
}
2reactions
pzanitticommented, Nov 14, 2018

If there is no standard/RFC that defines this, why was it decided that [] should be used? I understand a custom paramsSerializer 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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found