import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
export async function fetchValTownAPI(
apiToken: string,
path: string,
options?: RequestInit,
) {
if (!path.startsWith("/")) {
path = "/" + path;
}
if (!path.startsWith("/v1")) {
path = "/v1" + path;
}
return fetchJSON(`https://api.val.town${path}`, {
...options,
headers: {
"Authorization": `Bearer ${apiToken}`,
...(options?.headers || {}),
},
});
}