Send array of params on GET
See original GitHub issueHi, my issue is as follows:
I do a GET
request where the parameters include arrays. Eg:
GET /products?query=mug&categories=drinkware&categories=coffee
The server sees:
PARAMS:
{
"query" => "mug",
"categories" => ["drinkware", "coffee"]
}
How can I generate an address like that?
Currently I’m doing
searchProducts: (query, categories) ->
params = { query: query }
_.each categories, (cat, index) ->
params['categories'] = cat.name
Restangular.all('products').getList(params)```
But this only sends the last category as the parameter. I also tried:
```coffee
searchProducts: (query, categories) ->
params = { query: query }
_.each categories, (cat, index) ->
params['categories[' + index + ']'] = cat.name
Restangular.all('products').getList(params)
But the server receives that as an array of hashes
{
"query" => "mug",
"categories" => { "0" => "drinkware", "1" => "coffee" }
}
Any advice would be greatly appreciated!
I know that I could solve the issue by changing how I process the params (I could do a map down into an array, I could just do categories=JSON.stringify(category_names)
in the client, but I’ll bet there’s a pretty solution I’m missing.
Thank you.
Issue Analytics
- State:
- Created 9 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
How to pass an array within a query string? - Stack Overflow
Here's what I figured out: Submitting multi-value form fields, i.e. submitting arrays through GET/POST vars, can be done several different ...
Read more >Arrays in query params - Medium
Here is an example that leverages RAML Traits and Trait Parameters to define the fieldset that can be passed to a “fields” query...
Read more >Fun stuff: representing arrays and objects in query strings
getAll('user_ids') , you'll get an array containing the string "1,3" as a single item, instead of an array with two separate items.
Read more >Use the Query String to pass an array of selected values ...
Summary. You can pass data, including arrays via the Query String when using NavigationManager to navigate to a different page in your Blazor ......
Read more >How to pass an array as a URL parameter | Edureka Community
I would like to pass an array and added to a link on my page as a URL parameter, because later on the...
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
I recently ran into this issue and i had to do a bit of research to resolve the problem. The issue was closed but for anyone that might stumble on this problem here is a solution.
If you want to pass an array of items within angular all you need to do is store the property name with a open and close square brace:
I hope this help.
I confirm the issue that @gbittmann has. In my case, I’ve just passed simple key: array format:
This generates url with
&country=fr&country=pl