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

292
Visualizações
Get value from axios response header

I'm calling an API which returns some data and aditional information. This information is located in a custom header. For that I have the following code:

const CallAPI = async param => {
    await axios.get("api url...")
    .then(response => {
        var headerValues = response.headers['x-customName'];
        /*This prints something like this: 
        {"Parameter1":633,"Parameter2":10}*/
        console.log(headerValues);
    });
}

What I'm trying to do is to get the value of any of those parameters. I tried doing something like this:

console.log(headerValues["Parameter1"]);
console.log(headerValues.Parameter1);

But with both I'm getting undefined result. I also tried converting my response header result to JSON and trying the above console.log using the following code, but I'm getting the same results.

JSON.stringify(response.headers['x-customName']);

What I'm doing wrong or what can I do to get those values?

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

0

Try destructuring it:

.then({data}) => {
    console.log(data.parameter1);
}
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