Readme

trpc

Access private Val Town apis.

⚠️ trpc endpoints can change at any time

Available Produres (WIP)

Queries

  • search
  • getVal
  • getValMetadata
  • getValLastLogs

Mutations

  • deleteVal
  • updateReadme
  • togglePrivacy
  • updateVal
  • toggleLike
  • run
  • updateInterval
  • stopInterval
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const baseURL = `https://www.val.town/api/trpc`;
export const trpc = {
async query<T = any>(procedure: string, input: Record<string, unknown>) {
const url = new URL(`${baseURL}/${procedure}`);
url.searchParams.set("input", JSON.stringify(input));
const resp = await fetch(url, {
headers: {
authorization: `Bearer ${Deno.env.get("valtown")}`,
},
});
if (!resp.ok) {
throw new Error(await resp.text());
}
const { result } = await resp.json();
return result.data as T;
},
async mutate<T = any>(procedure: string, input: Record<string, unknown>) {
const resp = await fetch(new URL(`${baseURL}/${procedure}`), {
method: "POST",
headers: {
"content-type": "application/json",
authorization: `Bearer ${Deno.env.get("valtown")}`,
},
body: JSON.stringify(input),
});
if (!resp.ok) {
throw new Error(await resp.text());
}
const { result } = await resp.json();
return result.data as T;
},
};
👆 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.