how to change axios encoding for query in koa app?

  axios, encoding, javascript, koa

When sending an axios request in my Koa app, one of my query parameters has brackets as so:
lastTenDays:[now-10d TO now].

Here is the request:

const response = await this.axiosInstance.get('/somePath', {
      params: {
        query: query
        offset: 0,
        limit: 20,
        count: true
      }
    })

When I print the response.request, I notice there’s an axios field _currentUrl which shows the path of the request. In this case, it looks like this:
https://myBaseUrl.com/somePath?query=lastTenDays:[now-10d+TO+now]&offset=0&limit=20&count=true

Here’s what’s weird. If I encode my query parameter like this: lastTenDays:%5Bnow-10d+TO+now%5D, the _currentUrl doesn’t change at all!

It seems that when the brackets aren’t encoded, they don’t get encoded, and when they are encoded, they are decoded on the request. What’s going on? How can I prevent this so I can send the encoded brackets in th request?

Source: Ask Javascript Questions

LEAVE A COMMENT