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

134
Vistas
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 Respuestas
Responde la pregunta

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 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