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.

Support for multiple request params with same name?

See original GitHub issue

The current way of sending a GET request with query params like ?foo=5&bar=3 works like this:

axios.get('http://example.com/', { foo: 5, bar: 3 });

But since JS objects don’t support multiple fields with the same key, there’s no way to construct a request with multiple values for the same field (some APIs require this), such as this example:

http://example.com/?foo=5&bar=3&foo=7

I’d suggest adding a way to create the above URL by providing a list of arguments instead:

axios.get('http://example.com/', { bar: 3, foo: [5, 7] }

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:25
  • Comments:6

github_iconTop GitHub Comments

20reactions
Mahicommented, Mar 23, 2017

those are query params and not a js object as you mentioned

They are query params passed to get() as a JS object. get() then probably constructs the query param string out of the JS object.

I am currently using stringify(), but since there is clearly a built-in support for passing the query params as an object, why not improve it and add support for passing multiple params of the same key? Then we wouldn’t need stringify() anymore.

1reaction
adam-lynchcommented, Dec 6, 2017

Here’s an example using URLSearchParams: https://codepen.io/adam-lynch/pen/QORMyj. See the request in dev tools

Read more comments on GitHub >

github_iconTop Results From Across the Web

Correct way to pass multiple values for same parameter name ...
Most applications use the first option you have shown: http://server/action?id=a&id=b .
Read more >
Sure, multiple query params with the same name are...
To be clear, multiple params with the same name are valid — the standard wouldn't have the method getAll() if they weren't! But...
Read more >
How To Pass Multiple Parameters To Same Value in Query ...
While writing REST APIs, I've frequently needed to pass multiple values for the same parameter in a query string.
Read more >
REST Request node: multiple query string parameters ... - IBM
I am using IIB 10.0.0.12 to build an application that consumes an external REST API. The definition of the external API is provided...
Read more >
Retrofit — Multiple Query Parameters of Same Name
The Retrofit method to perform requests with multiple query parameters of the same name is done by providing a list of ids as...
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