Handle arrays as query parameter?
See original GitHub issueSay I need a function that works like this:
getThings(['a', 'b', 'c'], cb) // GET "/things?thing[]=a&thing[]=b&thing[]=c"
Currently, I have to do this:
function getThings(things, cb) {
var req = superagent.get('/things')
for (var i = 0; i < things.length; i++) {
req.query({thing: things[i]});
}
req.end(cb);
}
I would like to be able to do something like this instead:
function getThings(things, cb) {
superagent.get('/things')
.query({thing: things})
.end(cb);
}
Alternatively, use a different name for the array-enabled query method:
function getThings(things, cb) {
superagent.get('/things')
.queryArray('thing', things)
.end(cb);
}
Or is there a way to do this already, that I haven’t found?
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How to pass an array within a query string? - Stack Overflow
I want that query string value to be treated as an array- I don't want the array to be exploded so that it...
Read more >Arrays in query params - Medium
Arrays in query parameters are sometimes represented by repeating a ... each use-case, we'll see how to model that query parameter in RAML....
Read more >Fun stuff: representing arrays and objects in query strings
Decoding a query string into an array is done with parse_str. ... Also: it looks like it handled the array parameter, but it...
Read more >Use the Query String to pass an array of selected values ...
You can pass data, including arrays via the Query String when using NavigationManager to navigate to a different page in your Blazor app....
Read more >Angular - How to pass arrays via Query Parameters
This is a quick guide on how to pass an array of values via query string in Angular. This is working in Angular...
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
Well, qs can format query strings from arrays with no sweat.
Can be used with superagent easily:
However, I decided to use it with plain XMLHttpRequest in our project.
my issue originally came up because i wrote a library that is supposed to work on both node and client and has superagent as a dependency. a user reported an issue when using the client lib which i could not reproduce with my mocha tests (node). that’s why i reported it.
client and node libs have different behaviors – i don’t think that should be the case.