Open History to see the last commit
1export const getFilms = async () => {
2 const res = await fetch('https://swapi.dev/api/films/')
3 if (!res.ok) throw new Error('Failed to fetch films')
4 return await res.json()
5}
6β
7export const getFilm = async (filmId: string) => {
8 const res = await fetch(`https://swapi.dev/api/films/${filmId}/`)
9 if (!res.ok) throw new Error('Failed to fetch film')
10 return await res.json()
11}
12β
13export const getCharacters = async () => {
14 const res = await fetch('https://swapi.dev/api/people/')
15 if (!res.ok) throw new Error('Failed to fetch characters')
16 return await res.json()
17}
18β
19export const getCharacter = async (characterId: string) => {
20 const res = await fetch(`https://swapi.dev/api/people/${characterId}/`)
21 if (!res.ok) throw new Error('Failed to fetch character')
22 return await res.json()
23}
24β
25export const getPlanet = async (planetId: string) => {
26 const res = await fetch(`https://swapi.dev/api/planets/${planetId}/`)
27 if (!res.ok) throw new Error('Failed to fetch planet')
28 return await res.json()
29}