body data not sent in axios request

GET requests should not have a body.

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.

Leave a Comment