From 069f3aee53e77c1bf707dedc643180053d21cfae Mon Sep 17 00:00:00 2001 From: pomdtr Date: Thu, 18 Apr 2024 12:21:17 +0200 Subject: [PATCH] update all examples in the api section --- src/content/docs/api/vals.mdx | 122 +++++++++++++++++++--------------- 1 file changed, 67 insertions(+), 55 deletions(-) diff --git a/src/content/docs/api/vals.mdx b/src/content/docs/api/vals.mdx index 2218ea4..9d9e42e 100644 --- a/src/content/docs/api/vals.mdx +++ b/src/content/docs/api/vals.mdx @@ -11,14 +11,20 @@ The vals endpoints allow you to manipulate vals. Create a new val @@ -27,12 +33,18 @@ console.log(await createVal({ Create or update a val by name and code. @@ -51,11 +63,14 @@ console.log(await fetchJSON("https://api.val.town/v1/vals/7f9019e4-dbf8-4ebe-b8c Delete a val. @@ -64,11 +79,12 @@ console.log(await deleteVal({ List versions of a val @@ -77,23 +93,18 @@ console.log(await valVersions({ Create a new version of a val - 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, - }) - ))()); +import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON"; + +console.log(await fetchJSON("https://api.val.town/v1/vals/7f9019e4-dbf8-4ebe-b8cd-67730697624e/versions", { + method: "POST", + headers: { + "Content-Type": "application/json", + "Authorization": "Bearer " + Deno.env.get("valtown"), + }, + body: JSON.stringify({ + code: "const two = 2;", + }), +})); `.trim()} /> ## GET `/v1/vals/{val_id}/versions/{version}` @@ -101,12 +112,12 @@ console.log(await (() => Get a specific version of a val @@ -115,24 +126,25 @@ console.log(await valVersion({ Delete a val version. ## GET `/v1/vals/{val_id}/runs`