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

135
Visualizações
Covert fetch to axios in a javascript function

I need some help in replacing fetch with axios here

export const fetchSecret = async (secretName) => {
    const token = await getFunctionAppToken();
    const headers = {
        Authorization: `Bearer ${token}`,
    };
    const url = `${blbl.GetSecretFromVault}?secretName=${secretName}`;

    return Promise.all([fetch(url, { method: "get", headers })])
        .then(([response]) => {
            const res = response.text();
            return res;
        })
        .catch((error) => {
            return Promise.reject(error);
        });
};

I am stuck at the line of const res = response.text() for axios.

return Promise.all([axios.get(url, { headers })])
            .then(([response]) => {
                const res = ??????????
                return res;
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Axios automatically parses the response body stream as data, see response schema.

You can also inform Axios to expect a text response via the responseType option.

Finally, I always preference using the params option for passing query parameters as it ensures proper URL-encoding.

export const fetchSecret = async (secretName) =>
  (await axios.get(blbl.GetSecretFromVault, {
    headers: {
      Authorization: `Bearer ${await getFunctionAppToken()}`
    },
    params: { secretName },
    responseType: "text"
  })).data

I don't know why you were using Promise.all() so have omitted it.

Your .catch() was also redundant so it's not included either.


The (await axios.get(...)).data is just a shorter version of

const response = await axios.get(...)
return response.data

or without await...

return axios.get(...).then(response => response.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