Skip to content

Vals

The vals endpoints allow you to manipulate vals.

POST /v1/vals

Create a new val

ExampleRun in Val Town ↗
import { createVal } from "https://esm.town/v/nbbaier/createVal";
export const postVals = createVal({
token: Deno.env.get("valtown"),
name: "myNewVal",
code: "const two = 1 + 1;",
readme: "Lorem ipsum dolor sit amet.",
privacy: "public",
});

PUT /v1/vals

Create or update a val by name and code.

ExampleRun in Val Town ↗
import { updateValByName } from "https://esm.town/v/nbbaier/updateValByName";
export const updatedVal = updateValByName({
token: Deno.env.get("valtown"),
name: "myNewVal",
code: "const two = 2;",
});

GET /v1/vals/{val_id}

Get val by id.

ExampleRun in Val Town ↗
import { val } from "https://esm.town/v/neverstew/val";
export const getVal = val({
id: "7f9019e4-dbf8-4ebe-b8cd-67730697624e",
});

DELETE /v1/vals/{val_id}

Delete a val.

ExampleRun in Val Town ↗
import { deleteVal } from "https://esm.town/v/neverstew/deleteVal";
export const deleteValExample = deleteVal({
token: Deno.env.get("valtown"),
id: "1f32d4c1-332e-4135-889f-8df408924a9d",
});

GET /v1/vals/{val_id}/versions

List versions of a val

ExampleRun in Val Town ↗
import { valVersions } from "https://esm.town/v/neverstew/valVersions";
export const getValVersions = valVersions({
token: Deno.env.get("valtown"),
id: "0cfbf317-18a4-4da5-b887-b75bb8a33108",
});

POST /v1/vals/{val_id}/versions

Create a new version of a val

ExampleRun in Val Town ↗
import { createValVersion } from "https://esm.town/v/neverstew/createValVersion";
import { val as val2 } from "https://esm.town/v/neverstew/val";
export let createValVersionExample = (() =>
val2({
token: Deno.env.get("valtown"),
id: "543ae134-636f-43a7-bd7f-f766a3d52b47",
})
.then((val) => ({ id: val.id, code: val.code }))
.then(({ id, code }) =>
createValVersion({
token: Deno.env.get("valtown"),
code: `// my inserted comment
${code}`,
valId: id,
})
))();

GET /v1/vals/{val_id}/versions/{version}

Get a specific version of a val

ExampleRun in Val Town ↗
import { valVersion } from "https://esm.town/v/neverstew/valVersion";
export const getValVersion = valVersion({
token: Deno.env.get("valtown"),
id: "7f9019e4-dbf8-4ebe-b8cd-67730697624e",
version: 4,
});

DELETE /v1/vals/{val_id}/versions/{version}

Delete a val version.

ExampleRun in Val Town ↗
import { deleteValVersion } from "https://esm.town/v/neverstew/deleteValVersion";
export let deleteValVersionExample = deleteValVersion({
token: Deno.env.get("valtown"),
id: "543ae134-636f-43a7-bd7f-f766a3d52b47",
version: 1,
});

GET /v1/vals/{val_id}/runs

ExampleRun in Val Town ↗
import { valRuns } from "https://esm.town/v/neverstew/valRuns";
export const valRunsExample = valRuns({
token: Deno.env.get("valtown"),
id: "ae941dc9-97e5-4e2e-a25a-e07b733230ae",
limit: 1,
offset: 1,
});
Fork it on