Open History to see the last commit
1import type { Character, Paginated } from './types'
2β
3export const charactersAPI = {
4 getCharacters: async (): Promise<Paginated<Character>> => {
5 const res = await fetch('https://rickandmortyapi.com/api/character/')
6 if (!res.ok) throw new Error('Failed to fetch characters')
7 return await res.json()
8 },
9 getCharacter: async (characterId: string): Promise<Character> => {
10 const res = await fetch(
11 `https://rickandmortyapi.com/api/character/${characterId}`,
12 )
13 if (!res.ok) throw new Error('Failed to fetch character')
14 return await res.json()
15 },
16}