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

api.ts

30 lines826 Bytes

1export const getEpisodes = async () => {
2 const res = await fetch('https://rickandmortyapi.com/api/episode/')
3 return await res.json()
4}
5​
6export const getEpisode = async (episodeId: string) => {
7 const res = await fetch(
8 `https://rickandmortyapi.com/api/episode/${episodeId}`,
9 )
10 return await res.json()
12​
13export const getCharacters = async () => {
14 const res = await fetch('https://rickandmortyapi.com/api/character/')
15 return await res.json()
17​
18export const getCharacter = async (characterId: string) => {
19 const res = await fetch(
20 `https://rickandmortyapi.com/api/character/${characterId}`,
21 )
22 return await res.json()
24​
25export const getLocation = async (locationId: string) => {
26 const res = await fetch(
27 `https://rickandmortyapi.com/api/location/${locationId}`,
28 )
29 return await res.json()