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

161
Vistas
is it possible to return response from fetch with just promise (no async/await)

Why this doesn't work (I borrowed to https://jsfiddle.net/xlanglat/tyh6jjpy/):

  callWs2 = function(){
    let url = 'https://jsonplaceholder.typicode.com/posts/1';
    fetch(url)
    .then(function(response) {
      return response.text();
    })
  }

  console.log(callWs2());
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

.then method returns a Promise and in your case it returns a Promise that resolves with whatever response.text() resolves with. Note: response.text() also returns a Promise.

Returns another pending promise object, the resolution/rejection of the promise returned by then will be subsequent to the resolution/rejection of the promise returned by the handler. Also, the resolved value of the promise returned by then will be the same as the resolved value of the promise returned by the handler. Source.

Now, you need to return this Promise from your function.

And finally when you're calling the function you need to chain it with .then because the function returns a Promise.

function callWs2() {
  let url = 'https://jsonplaceholder.typicode.com/posts/1';
  return fetch(url)
    .then(function(response) {
      const res = response.text();
      console.log(res instanceof Promise); // true
      return res;
    })
}

callWs2().then(console.log);

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