Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

192
Vistas
how pass a var in the axios?

I'm trying to pass a var to the axios more by what I'm seeing it just accepts string is there any way to pass a var ?

My code:

router.get('/albuns', async (req, res)=>{
  const response = await axios.get(req.query.id)

  return console.log(response)
})

Error:

Argument of type 'string | ParsedQs | string[] | ParsedQs[] | undefined' is not assignable to parameter of type 'string'.

Type 'undefined' is not assignable to type 'string'.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

This is just a Typescript warning because axios.get() expects a string argument but the default req.query can provide various types.

You just need to cast the value

const response = await axios.get(req.query.id as string);

Another option is to type the request in your handler signature

import { Request } from "express";

interface AlbunsQuery {
  id: string;
}

type AlbunsRequest = Request<{}, any, any, AlbunsQuery>;

router.get("/albuns", async (req: AlbunsRequest, res) => {
  const response = await axios.get(req.query.id);

  // etc
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

URL parameters aren't supported, and it seems they have no intention on adding it, given they expect you to use template strings. Here there's a discussion: https://github.com/axios/axios/issues/706

Axios GET method takes two arguments: the first being the URL string, and the second argument, we have it configure object with the property called params.

Axios Code:

axios.get("http://localhost/example"){
       params{
          name: myName
          example: 2
}}

Express Code:

app.get("example", (req, res){
const name : request.query.name
const example: request.query.example
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda