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

11 lines
253 B
TypeScript
Raw Normal View History

// 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>
})
}