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

api.ts

11 lines351 Bytes

1import type { PlanetsPage } from './types'
2​
3const endPoint = 'https://swapi.dev/api'
4​
5export const planetsAPI = {
6 getPlanets: async (page: number): Promise<PlanetsPage> => {
7 const response = await fetch(`${endPoint}/planets/?page=${page}`)
8 if (!response.ok) throw new Error('Failed to fetch planets')
9 return await response.json()
10 },