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

153
Vistas
How to specify headers in an axios request in an async function?

I'm trying to fetch data from a public API and I have to specify the headers in the axios get request function to get a content type of application/json as and return a response.

let joke;

async function getJoke() {
  try {
    const res = await axios.get('https://icanhazdadjoke.com/', { headers: { 'Accept':'application/json' } });
    joke = res.data;
    console.log(res);
  } catch (error) {
    console.log(`Error Logged : Status code returned is ${error.response.status}`);
  }
}

getJoke();

I've tried both, 'Content-Type' : 'application/json' and 'Accept': 'application/json' in an attempt not to fall into the error, but it's still catching the error and logging it.

about 4 years ago · Juan Pablo Isaza
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