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

api.ts

24 lines723 Bytes

1export const getFilms = async () => {
2 const res = await fetch('https://swapi.dev/api/films/')
3 return await res.json()
4}
5​
6export const getFilm = async (filmId: string) => {
7 const res = await fetch(`https://swapi.dev/api/films/${filmId}/`)
8 return await res.json()
9}
10​
11export const getCharacters = async () => {
12 const res = await fetch('https://swapi.dev/api/people/')
13 return await res.json()
15​
16export const getCharacter = async (characterId: string) => {
17 const res = await fetch(`https://swapi.dev/api/people/${characterId}/`)
18 return await res.json()
20​
21export const getPlanet = async (planetId: string) => {
22 const res = await fetch(`https://swapi.dev/api/planets/${planetId}/`)
23 return await res.json()