Readme

Fetch data from the val town api

Usage

Create an helper val

const valtownApi = (path: string, options?: RequestInit) => @pomdtr.fetchValTownAPI( @me.secrets.apiToken, path, options, );

Then use it in any of your val

@me.valtownApi("/alias/pomdtr")
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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 || {}),
},
});
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023