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

api.ts

16 lines559 Bytes

1import type { Episode, Paginated } from './types'
2​
3export const episodesAPI = {
4 getEpisodes: async (): Promise<Paginated<Episode>> => {
5 const res = await fetch('https://rickandmortyapi.com/api/episode/')
6 if (!res.ok) throw new Error('Failed to fetch episodes')
7 return await res.json()
8 },
9 getEpisode: async (episodeId: string): Promise<Episode> => {
10 const res = await fetch(
11 `https://rickandmortyapi.com/api/episode/${episodeId}`,
12 )
13 if (!res.ok) throw new Error('Failed to fetch episode')
14 return await res.json()
15 },