Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

api.ts

18 lines605 Bytes

1import type { Pokemon, PokemonList } from './types'
2​
3const MAX_POKEMONS = 100
4​
5export const pokemonsAPI = {
6 getPokemons: async (): Promise<PokemonList> => {
7 const response = await fetch(
8 `https://pokeapi.co/api/v2/pokemon?limit=${MAX_POKEMONS}`,
9 )
10 if (!response.ok) throw new Error('Failed to fetch pokemons')
11 return await response.json()
12 },
13 getPokemon: async (id: string): Promise<Pokemon> => {
14 const response = await fetch(`https://pokeapi.co/api/v2/pokemon/${id}`)
15 if (!response.ok) throw new Error('Failed to fetch pokemon')
16 return await response.json()
17 },