Fetching Data from an API call
Fetch is in the frontmatter
bulbasaur
ivysaur
venusaur
charmander
charmeleon
//src/pages/experiments/data-fetching.astro
---
import BaseLayout from '../../layouts/BaseLayout.astro';
const allPokemonResponse = await fetch(`https://pokeapi.co/api/v2/pokemon?limit=5`);
const allPokemonResult = await allPokemonResponse.json();
const allPokemon = allPokemonResult.results;
---
<BaseLayout title="Data Fetching" >
<h1>Fetching data from an API call</h1>
<h3>Fetch is in the frontmatter</h3>
{allPokemon.map((pokemon) => (<p>{pokemon.name}</p>))}
</BaseLayout>