Skip to content

Run

The Run API lets you run any Val as an API. Unauthenticated use will only have access to public vals. If you run a JSON Val, it simply returns that Val. A function Val will be executed its author’s permissions, so it will be able to read and write to author’s public and private vals, read their environment variables, and send them emails via std/email.

You pass args to Run API function calls via a JSON-encoded array. While it may feel a bit clunky to always pass an array (even when passing a single argument), this is a clean and expressive way to accept any number of arguments.

GET /v1/run/{username}.{val_name}

ExampleRun in Val Town ↗
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
export let runGET = fetchJSON(
`https://api.val.town/v1/run/stevekrouse.add?args=${JSON.stringify([1, 2])}`
);

POST /v1/run/{username}.{val_name}

ExampleRun in Val Town ↗
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
export let runPOST = fetchJSON(`https://api.val.town/v1/run/stevekrouse.add`, {
method: "POST",
body: JSON.stringify({
args: [1, 2],
}),
});
Fork it on