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

388
Visualizações
PokeAPI Javascript only retrieved name and URL

I want to access to the Pokémon types in the json file.

However, it looks like I can only retrieve name and url, any idea of what am I doing wrong?

const baseUrl = 'https://pokeapi.co/api/v2/pokemon/?limit=3000'
try {
    fetch(baseUrl)
        .then(response => {
            const responseJson = response.json()
            return responseJson
        })
        .then(data => {
            const pokemons = data.results
            pokemons.forEach(pokemon => {
                console.log(pokemon);
            })
        })
        .catch(error => {
            console.error(error)
        })
} catch (error) {
    console.error(error)
}

enter image description here

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

0

Actually, this is how the API is done.

If you want to get more values about pokemons, you need to make another request by the given URL from the first result.

This can be done using another axios call inside the then

const baseUrl = 'https://pokeapi.co/api/v2/pokemon/?limit=1'
try {
    fetch(baseUrl)
        .then(response => {
            const responseJson = response.json()
            return responseJson
        })
        .then(async data => {
            const pokemons = data.results
            for (const pokemon of pokemons){
              pokemon.data = await fetch(pokemon.url).then(res => res.json())
            }
            
            console.log(pokemons)
        })
        .catch(error => {
            console.error(error)
        })
} catch (error) {
    console.error(error)
}

Note that the API is quite slow that's why I would recommand using pagination instead of limit=3000 ad you did.

This can be done using the offsetparameter which is the start of the pagination

For example, ?offset=20&limit=20 will get the 20 pokemons betwenn 20 and 40

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