taevas.xyz/netlify/functions/shared/api.ts

10 lines
253 B
TypeScript

// Standard variation
export async function api<T>(url: string): Promise<T> {
return fetch(url)
.then(response => {
if (!response.ok) {
throw new Error(response.statusText)
}
return response.json() as Promise<T>
})
}