Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

211
Visualizações
axios.get not passing params from client side to the server

As the title, axios.get not passing params from client side to the server. My server is currently on localhost:3001, and my client side is on http://127.0.0.1:5555. Client side is not React, so it's currently on http://127.0.0.1:5555/WeatherApp/index.html (I opened the index.html file, the "entry point of the app," on chrome from vscode by using FiveServer, and it is the port the client is being hosted)

Client side code:

export async function fetchData() {
  const { data } = 
  await axios.get('http://localhost:3001/api', {
    params: {q: 'Paris'}
  })
  return data
}

Server side code:

app.get("/api", async (req, res) => {
  console.log(req.query)
  const response = await axios.get('http://api.weatherapi.com/v1/current.json', {
    params: {
      key: process.env.KEY,
      q: 'Paris'
    }
  })
  const { data } = response
  res.send(data)
})

The console.log(req.query) in server code printed an empty object. I also tried req.params, but it also printed an empty object (while i want to see "Paris"). Tried console.log(req) to see where the word "Paris" might be nested, but nowhere to be found.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

If you want to send a body with your request, you'd be looking to make a POST request, as GET as you dont pass a body with it, but you can use parameters in your URL to pass information to the sever in a GET request

You can read more here

about 4 years ago · Juan Pablo Isaza Relatório

0

I'm using these two code snippets and it actually works... Maybe you're missing something essential:

server.js

const express = require('express')
const app = express()
const port = 3000

app.get('/api', (req, res) => {
  console.log(req.query)
  res.send('Hello World!')
})

app.listen(port, () => {
    console.log(`Example app listening on port ${port}`)
})

client.js

const axios = require('axios');

axios.get('http://localhost:3000/api', {
      params: {q: 'Paris'}    
}).then(({data}) => console.log(data));
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda