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

api.ts

14 lines545 Bytes

1import type { Character, Paginated } from './types'
2​
3export const charactersAPI = {
4 getCharacters: async (): Promise<Paginated<Character>> => {
5 const res = await fetch('https://swapi.dev/api/people/')
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(`https://swapi.dev/api/people/${characterId}/`)
11 if (!res.ok) throw new Error('Failed to fetch character')
12 return await res.json()
13 },