diff options
Diffstat (limited to 'js/seed/src/api.js')
-rw-r--r-- | js/seed/src/api.js | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/js/seed/src/api.js b/js/seed/src/api.js new file mode 100644 index 0000000..d50c644 --- /dev/null +++ b/js/seed/src/api.js @@ -0,0 +1,15 @@ +// api.js +// API fetch logic + +/** + * Fetch a Pokémon by name from the PokéAPI + * @param {string} name + * @returns {Promise<object>} Pokémon data + */ +export async function fetchPokemon(name) { + const res = await fetch(`https://pokeapi.co/api/v2/pokemon/${encodeURIComponent(name.toLowerCase())}`); + if (!res.ok) { + throw new Error('Pokémon not found'); + } + return await res.json(); +} \ No newline at end of file |