[Fixed] Request body is an empty object / axios / express

Issue

When making a get request with axios like:

  getInformation(name) {
    var data = {
      sName: name
    };
    
    return instance
      .get('/getSeason/', data)
      .then((res) => {
        console.log(res);
      });
  }

and accessing the request body I get an empty object.
Body-Parser is used in app.js. When making the request with query strings I can read the req.query.
Content type is set to: 'Content-Type': 'application/json',

Solution

axios.get function’s second parameter refers to options configuration. You cannot send data in axios.get a request in the second parameter. Refer axios.get signature.

Leave a Reply

(*) Required, Your email will not be published