Axios GET with Data

Sep 8, 2020

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

That's because, while the HTTP spec does not specifically forbid sending a request body with a GET request, older versions of the HTTP spec say that HTTP servers should ignore GET request bodies. So most HTTP services don't support GET request bodies.

Use params Instead

Instead of sending your data using the data parameter, you can use the params option to tell Axios to put your parameters in the query string:

const axios = require('axios');

// Equivalent to `axios.get('')`
const res = await axios.get('', { params: { answer: 42 } });; // { answer: 42 }

More Axios Tutorials