Public
Script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { fetch } from "https://esm.town/v/std/fetch";
export async function run(
{ username, valName, data, token }: Params,
): Promise<Result> {
let url = `https://api.val.town/v1/run/${username}.${valName}`;
const headers: HeadersInit = {};
if (token)
headers.Authorization = `Bearer ${token}`;
const method = data ? "POST" : "GET";
const body = data ? JSON.stringify({ args: data }) : undefined;
const response = await fetch(url, { method, headers, body });
return await response.json();
}
type Args = unknown[];
type Params = {
username: string;
valName: string;
data?: Args;
token?: string;
};
type Result = unknown;
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