Axios API is a bit different from the jQuery AJAX one. If you have to pass some params along with GET request, you need to use params property of config object (the second param of .get() method):

axios.get('/api/updatecart', {
  params: {
    product: this.product
  }
}).then(...)

You can pass either a plain object or a URLSearchParams object as params value.

Note that here we're talking about params appended to URL (query params), which is explicitly mentioned in the documentation.

If you want to send something within request body with GET requests, params won't work - and neither will data, as it's only taken into account for PUT, POST, DELETE, and PATCH requests. There're several lengthy discussions about this feature, and here's the telling quote:

Unfortunately, this doesn't seem to be an axios problem. The problem seems to lie on the http client implementation in the browser javascript engine.

According to the documentation and the spec XMLHttpRequest ignores the body of the request in case the method is GET. If you perform a request in Chrome/Electron with XMLHttpRequest and you try to put a json body in the send method this just gets ignored.

Using fetch which is the modern replacement for XMLHtppRequest also seems to fail in Chrome/Electron.

Until it's fixed, the only option one has within a browser is to use POST/PUT requests when data just doesn't fit into that query string. Apparently, that option is only available if corresponding API can be modified.

However, the most prominent case of GET-with-body - ElasticSearch _search API - actually does support both GET and POST; the latter seems to be far less known fact than it should be. Here's the related SO discussion.

Answer from raina77ow on Stack Overflow
🌐
GitHub
github.com › axios › axios › issues › 2400
how to send data in body with get request · Issue #2400 · axios/axios
September 10, 2019 - in elastic search,recommend fetch data by get else not post Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered. Additional context Add any other context or screenshots about the feature request here.
Author   wsyqn6
Top answer
1 of 1
177

Axios API is a bit different from the jQuery AJAX one. If you have to pass some params along with GET request, you need to use params property of config object (the second param of .get() method):

axios.get('/api/updatecart', {
  params: {
    product: this.product
  }
}).then(...)

You can pass either a plain object or a URLSearchParams object as params value.

Note that here we're talking about params appended to URL (query params), which is explicitly mentioned in the documentation.

If you want to send something within request body with GET requests, params won't work - and neither will data, as it's only taken into account for PUT, POST, DELETE, and PATCH requests. There're several lengthy discussions about this feature, and here's the telling quote:

Unfortunately, this doesn't seem to be an axios problem. The problem seems to lie on the http client implementation in the browser javascript engine.

According to the documentation and the spec XMLHttpRequest ignores the body of the request in case the method is GET. If you perform a request in Chrome/Electron with XMLHttpRequest and you try to put a json body in the send method this just gets ignored.

Using fetch which is the modern replacement for XMLHtppRequest also seems to fail in Chrome/Electron.

Until it's fixed, the only option one has within a browser is to use POST/PUT requests when data just doesn't fit into that query string. Apparently, that option is only available if corresponding API can be modified.

However, the most prominent case of GET-with-body - ElasticSearch _search API - actually does support both GET and POST; the latter seems to be far less known fact than it should be. Here's the related SO discussion.

Discussions

HTTP GET request with a body??
On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge. If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options: Limiting your involvement with Reddit, or Temporarily refraining from using Reddit Cancelling your subscription of Reddit Premium as a way to voice your protest. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/learnprogramming
13
1
March 5, 2024
Data payload body should be applicable for request methods 'GET'
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. ... There was an error while loading. Please reload this page. ... // `data` is the data to be sent as the request body // Only applicable for request methods 'PUT', 'POST', 'DELETE', and 'PATCH' I understand that axios ... More on github.com
🌐 github.com
5
July 23, 2022
reactjs - How to send body data and headers with axios get request? - Stack Overflow
So you cannot put it in the config-object. And the signature of the axios#get-method does not provide a data parameter. ... First of all this is not possible to pass a request body with get method. More on stackoverflow.com
🌐 stackoverflow.com
axios get request with body and header - javascript
If you read the axios config documentation, you will find · // data is the data to be sent as the request body // Only applicable for request methods 'PUT', 'POST', 'DELETE , and 'PATCH' You can read more at HTTP GET with request body for the reasons. More on stackoverflow.com
🌐 stackoverflow.com
🌐
Apidog
apidog.com › blog › axios-get-with-body-and-header
How to make Axios API GET Request with Body and Headers
February 4, 2026 - If you find yourself needing to ... GET requests, it’s important to understand that the HTTP specification typically does not include a request body for GET requests....
🌐
GitHub
github.com › axios › axios › issues › 4878
Data payload body should be applicable for request methods 'GET' · Issue #4878 · axios/axios
July 23, 2022 - As described in the doc, Data is not applicable for request methods 'GET' // `data` is the data to be sent as the request body // Only applicable for request methods 'PUT', 'POST', 'DELETE', and 'PATCH' I understand that axios at first f...
Author   Phenek
🌐
Mastering JS
masteringjs.io › tutorials › axios › get-with-data
Axios GET with Data - Mastering JS
September 8, 2020 - So most HTTP services don't support GET request bodies. 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:
Find elsewhere
🌐
Mastering JS
masteringjs.io › tutorials › axios › response-body
Get the HTTP Response Body with Axios - Mastering JS
July 23, 2020 - const axios = require('axios'); ... succeeded, so you will often see code that gets the response body directly using promise chaining....
🌐
Axios
axios-http.com › docs › req_config
Request Config | Axios Docs
Allows consumer to control how params are serialized. indexes: false // array indexes format (null - no brackets, false (default) - empty brackets, true - brackets with indexes) }, // `data` is the data to be sent as the request body // Only applicable for request methods 'PUT', 'POST', 'DELETE', and 'PATCH' // When no `transformRequest` is set, must be of one of the following types: // - string, plain object, ArrayBuffer, ArrayBufferView, URLSearchParams // - Browser only: FormData, File, Blob // - Node only: Stream, Buffer data: { firstName: 'Fred' }, // syntax alternative to send data into the body // method post // only the value is sent, not the key data: 'Country=Brasil&City=Belo Horizonte', // `timeout` specifies the number of milliseconds before the request times out.
🌐
Educative
educative.io › answers › how-to-make-an-axios-get-request
How to make an Axios GET request
The HTTP get request is performed by calling axios.get(). The get() method requires two parameters to be supplied to it. First, it needs the URI of the service endpoint. Second, it should be passed an object that contains the properties we want to send to our server. Passing a data object as a parameter to the post method is optional; therefore, ​the post method is very​ similar to the get method. Axios is a promise-based library.
🌐
Form.io
mindbowser.com › home › blogs › how to send a raw data body to an axios request in react native?
How to Send Raw Data Body to Axios Request in React Native?
January 25, 2024 - To Send a Raw Data Body to an Axios Request in React Native you just have your raw text within body or pass it directly within quotes as 'raw text to be sent' in place of body
🌐
GitHub
github.com › axios › axios
GitHub - axios/axios: Promise based HTTP client for the browser and node.js · GitHub
5 days ago - ... const response = await ... { const acct = results[0]; const perm = results[1]; }); Requests can be made by passing the relevant config to axios....
Starred by 109K users
Forked by 11.6K users
Languages   JavaScript 86.5% | TypeScript 11.6% | HTML 1.9%
Top answer
1 of 6
27

Not all clients and servers support body in GET request. In this case, the browser can't send body in GET request (axios supports sending body in GET request).

As a workaround, you can change the method from 'GET' to 'POST'

Like so:

axios.request({
  method: 'POST',
  url: `http://localhost:4444/next/api`,
  headers: {
    'Authorization': token
  },
  data: {
    next_swastik: 'lets add something here'
  },

})

and change your api to expect a post

app.post('/next/api', verifyToken, function(req, res) {
console.log(req.body);
});

or

Change the data property to params

axios.request({
  method: 'GET',
  url: `http://localhost:4444/next/api`,
  headers: {
    'Authorization': token
  },
  params: {
    next_swastik: 'lets add something here'
  },

})

and change the api to log out the params

app.get('/next/api', verifyToken, function(req, res) {
console.log(req.params);
});

and like @MaieonBrix said, make sure that your headers contain the content type that you are sending.

2 of 6
10

It looks like you only have two points left to make it work :

  • one : the http method should be set to POST instead of GET since you want to send something.

  • two : you can then add the http header (like what you did with the authorization header) Content-Type: 'application/json`

On the back-end don't forget to use some kind of body parser utility package like this one : body-parser and set it up with your app.

I suppose your server is using express, here is how you will do it with express :

const express = require('express');
const app = express();
const bodyParser = require('body-parser')
const jsonParser = bodyParser.json();

app.use(jsonParser); // use it globally
app.get('your_route', jsonParser, otherMiddleware, (req, res) => ...); // use it for specific routes

/* ... rest of your code */
🌐
Apidog
apidog.com › blog › axios-body-post-request
How to Add Body to Post Request with Axios
February 4, 2026 - Learn the simple and effective method to include a body in post requests using Axios with our step-by-step guide.
🌐
Axios
axios-http.com › docs › api_intro
Axios API | Axios Docs
Axios API The Axios Instance Request Config Response Schema Config Defaults Interceptors Handling Errors Cancellation 🆕 URL-Encoding Bodies 🆕 Multipart Bodies ... Requests can be made by passing the relevant config to axios. // Send a POST request axios({ method: 'post', url: '/user/12345', ...
🌐
GitHub
github.com › axios › axios › issues › 787
GET request does not send data (JSON). · Issue #787 · axios/axios
March 24, 2017 - axios.get("/api/v1/post/allFromUser", {data: {"author": "fharding"}}).then(response => { this.posts = response.data; }).catch(err => { alert(err); console.log(err); }) When I switch this to POST the data get's send just find, but there is no body when sent with GET.
Author   ghost