So the backend (not under my control) requires a query string like this:
http://example.com/?foo=5&foo=2&foo=11
But axios
uses JS object to send the request params:
axios.get('http://example.com/', { foo: 5 });
And obviously such object can't have multiple fields with the same key.
How can I send a request with multiple fields with same key?
Adding more details to @nhydock accepted answer. When you do
axios.get('http://example.com/', request);
For django application you can receive these as
also.
To use this in a request, you would do
The only issue with using a plain object approach is that array parameters are added as
To get request without the
[]
like you want, you can use the URLSearchParamsThis will result in a request as
It might also be possible to pass arrays as values for the parameter:
axios.get('http://example.com/', { foo: [1, 2, 3, 4, 5] });
If one uses the ready URLSearchParams the handling of multiple parameter values with the same name works with axios as well ... I guess the support for IE came in 2017 ... Works on Safari too, although the links claims that it might not ..
In Axios request config, you can override params serialization and then use QS NPM module to serialize array with repeat mode