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

145
Vistas
Javascript Fetch API can't control the coming response

I am trying to fetch some information from the given URL. I assigned the URL to a const named URL. I used the fetch api to take the info from the source as JSON format. I can't control the coming information.Here is my code;

const fetch = require("cross-fetch");
const URL = "https://anapioficeandfire.com/api/books"


// Important: Don't change the function name
const getBooks = async () => {
  // Your code goes here
  
  
  const response = await fetch(`${URL}`)
    .then(res => res.json())
    .then(data => console.log(data));
  const books = await response.json();
  return books;
}

getBooks().then(books => console.log(books))

This is the response from the code that I wrote
I only need the
{
name: "...",
numberOfPages: "....",
released: "......",
},
{
name: "...",
numberOfPages: "....",
released: "......",
},
....

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Return the values that you need from the api response. Here is the how you can do it:

const url = "https://anapioficeandfire.com/api/books";

const callApi = async () => {
const resp = await fetch(url);
const finalRes = await resp.json();
return finalRes.map((res) => {
    return {
    name: res.name,
    numberOfPages: res.numberOfPages,
    released: res.released,
    };
});
};

(async () => console.log(await callApi()))();

Result set from browser console:

enter image description here Also, while waiting for promise to get fulfilled, you can do .then() or use await. They both solve the same purpose.

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