Readme

Val Town API URL

When Val Town code is run on Val Town servers we use a local URL so we can save time by skipping a roundtrip to the public internet. However, if you want to run your vals that use our API, ie std library vals, locally, you'll want to use our public API's URL, https://api.val.town. We recommend importing and using std/API_URL whenever you use our API so that you are always using the most efficient route.

Example Usage

Create valimport { API_URL } from "https://esm.town/v/std/API_URL"; const response = await fetch(`${API_URL}/v1/me`, { headers: { Authorization: `Bearer ${Deno.env.get("valtown")}`, Accept: "application/json", }, }); const data = await response.json(); console.log(data)
1
2
3
4
5
6
7
8
function envOrUndefined(key: string): string | undefined {
// try/catch prevents crashes if the script doesn't have env access
try {
return Deno.env.get("VALTOWN_API_URL");
} catch {}
}
export const API_URL = envOrUndefined("VALTOWN_API_URL") ?? "https://api.val.town";
๐Ÿ‘† This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data โ€” all from the browser.