taevas.xyz/netlify/functions/shared/api.ts
2023-05-07 19:48:02 +02:00

11 lines
263 B
TypeScript

import fetch from "node-fetch"
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>
})
}