Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Axios get in url works but with second parameter as object it doesn't

People also ask

How send parameters in HTTP GET request?

To use this function you just need to create two NameValueCollections holding your parameters and request headers. Show activity on this post. You can also pass value directly via URL. If you want to call method public static void calling(string name){....}

Can we pass data in GET request in Axios?

Axios' post() function supports a data parameter that becomes the HTTP request body. On the other hand, axios. get() does not support this parameter.

Can we send JSON in GET request Axios?

POST JSON with AxiosIf you send a serialized JSON object as data, however, Axios considers it as “application/x-www-form-urlencoded” (form-encoded request body). You must manually set the header using the “headers” config option if the intended content type is JSON.


axios.get accepts a request config as the second parameter (not query string params).

You can use the params config option to set query string params as follows:

axios.get('/api', {
  params: {
    foo: 'bar'
  }
});

On client:

  axios.get('/api', {
      params: {
        foo: 'bar'
      }
    });

On server:

function get(req, res, next) {

  let param = req.query.foo
   .....
}

This works fine for me. When it is post request nested data object isn't needed but in get requests, in order to send data, you need it.

axios.get('/api', {
    data: {
        foo: 'bar'
    }
}