Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
Axios not sending body

Axios not sending body to my API.

router.get('/login', async function(req,res) {
  try {
    const email  = req.body.email;
    const pass  = req.body.pass;
    const users = await pool.query("select username from users where username=$1 and password=$2", [email, pass]);
    if(users.rows[0])
      res.json(users.rows[0]['username']!=null);
    else
      res.json(users)
      console.log(req.body)
    console.log(email,pass)
  } catch (err) {
    console.log(err.message);
  }
});

When I console.log the req.body it after running GetData

async function GetData() {

    const email = document.getElementById("email").value;
    const pass = document.getElementById("pass").value;
    const response = await axios.get("http://localhost:3002/login",
    {
      body: JSON.stringify({"email":  email, "pass" : pass})
    })
    console.log(response.config.body);
    console.log(response.data.rows)
  }

The body is said to be {} an empty object.

How do I send the body through axios the same way insomnia is sending a body.

When using insomnia and the exact same body it returns true as it should. enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

GET doesn’t accept sending a body, use POST instead:

router.post('/login', async function(req,res) {

// …

const response = await axios.post("http://localhost:3002/login", { email, pass })

Also, the response.config.body is not a thing, if you look at request config documentation, there is the property “data”, rather than “body”.

console.log(response.config.data);

Hopefully that helps!

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!