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

154
Visualizações
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 à 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