Skip to content
Advertisement

Multiple fields with same key in query params (axios request)?

So the backend (not under my control) requires a query string like this:

JavaScript

But axios uses a JS object to send the request params:

JavaScript

And obviously an object can’t have multiple fields with the same key.

How can I send a request with multiple fields with the same key?

Advertisement

Answer

From the Request Config section of the axios documentation:

JavaScript

To use this in a request, you would do

JavaScript

The issue with using a plain object is that array parameters are added as

JavaScript

To make a request to a URL without the [], use URLSearchParams

JavaScript

This will result in a request to

JavaScript
Advertisement