211Make an HTTP val (other vals are currently not supported to run, even though we have examples for them).
212Start your response with a comment explaining how your approach will work, what libraries or
213API calls you will use, and any tradeoffs you're making. Then write the code in a consise way,
214the simplest way to achieve the goal, though you can add some inline comments to explain your
215reasoning (not for every line, but for major groups of lines). Don't use any environment variables
216unless strictly necessary, for example use APIs that don't require a key, prefer internal function
217imports (using esm.town), and prefer putting API keys as inline variables. Use built-in Deno
218functions where possible. Unless specified, don't add error handling,
219make sure that errors bubble up to the caller.
220Avoid external images or base64 images, use emojis, unicode symtols, or icon fonts/libraries instead, unless that's
221not practical for the user's request (e.g. if they ask for a particular animated gif).
222If the user asks for something that requires persistence, use the Val Town Blob storage API, unless
223explicitly specified otherwise. Use the current val name for the storage key, which you can get
224using the "pomdtr/extractValInfo" val, which you can call like this:
273Make an HTTP val (other vals are currently not supported to run, even though we have examples for them).
274Add comments at the top of the file explaining how your approach works, what libraries or
275API calls you will use, and any tradeoffs you're making. Then write the code in a consise way,
276the simplest way to achieve the goal, though you can add some inline comments to explain your
277reasoning (not for every line, but for major groups of lines). Don't use any environment variables
278unless strictly necessary, for example use APIs that don't require a key, prefer internal function
279imports (using esm.town), and prefer putting API keys as inline variables. Use built-in Deno
280functions where possible. Unless specified, don't add error handling,
281make sure that errors bubble up to the caller.
282Avoid external images or base64 images, use emojis, unicode symtols, or icon fonts/libraries instead, unless that's
283not practical for the user's request (e.g. if they ask for a particular animated gif).
284If the user asks for something that requires persistence, use the Val Town Blob storage API, unless
285explicitly specified otherwise. Use the current val name for the storage key, which you can get
286using the "pomdtr/extractValInfo" val, which you can call like this:
389\`\`\`
390
391### Lower-level API
392
393We do provide access to the lower-level getter and setters, which are useful if you are storing non-JSON or binary data, need to stream in your response or request data, or do anything else lower-level.
394
395- \`async get(key: string)\`: Retrieves a blob for a given key.
396- \`async set(key: string, value: string | BodyInit)\`: Sets the blob value for a given key. See [BodyInit](https://deno.land/api@v1.38.1?s=BodyInit).
397
398### Limitations
12041205const tempValName = `valle_tmp_${Math.random() * 10}`.replaceAll(".", "");
1206// Errors in running the val bubble up through this API, so ignore them.
1207await vt.vals.create({ name: tempValName, code: newCode, type: "http" as any, privacy: "unlisted" }).catch(
1208(error) => {
3637async function enhancedWikipediaSearch(pageName: string): Promise<any | null> {
38const apiUrl = new URL("https://en.wikipedia.org/w/api.php");
39apiUrl.searchParams.append("action", "query");
40apiUrl.searchParams.append("list", "search");
41apiUrl.searchParams.append("srsearch", pageName);
42apiUrl.searchParams.append("srnamespace", "0");
43apiUrl.searchParams.append("srlimit", "1");
44apiUrl.searchParams.append("format", "json");
4546const response = await fetch(apiUrl.toString());
47const data = await response.json();
4860}
6162const apiUrl = new URL("https://en.wikipedia.org/w/api.php");
63apiUrl.searchParams.append("action", "query");
64apiUrl.searchParams.append("titles", searchResult.title);
65apiUrl.searchParams.append("prop", "pageimages|extracts|info|images|pageprops");
66apiUrl.searchParams.append("piprop", "original|name");
67apiUrl.searchParams.append("pithumbsize", "1000");
68apiUrl.searchParams.append("pilimit", "1");
69apiUrl.searchParams.append("exintro", "1");
70apiUrl.searchParams.append("explaintext", "1");
71apiUrl.searchParams.append("redirects", "1");
72apiUrl.searchParams.append("inprop", "url");
73apiUrl.searchParams.append("format", "json");
7475const response = await fetch(apiUrl.toString());
76const data = await response.json();
7778console.log("API Response:", JSON.stringify(data, null, 2));
7980if (!data.query || !data.query.pages) {
134filename = filename.replace(/^File:/, "");
135136const apiUrl = new URL("https://en.wikipedia.org/w/api.php");
137apiUrl.searchParams.append("action", "query");
138apiUrl.searchParams.append("titles", `File:${filename}`);
139apiUrl.searchParams.append("prop", "imageinfo");
140apiUrl.searchParams.append("iiprop", "url|size");
141apiUrl.searchParams.append("format", "json");
142143const response = await fetch(apiUrl.toString());
144const data = await response.json();
145
14}
15try {
16// https://api.twitch.tv/helix/schedule/icalendar?broadcaster_id=95536715
17const url = new URL("https://api.twitch.tv/helix/schedule/icalendar");
18url.searchParams
19.set("broadcaster_id", params.get("broadcaster_id"));
YouTubeSubmissionsmain.tsx3 matches
2// We'll use the built-in Request and Response objects for handling HTTP.
3// The form fields are customized for video information collection.
4// We'll add JSON API endpoints for Framer Fetch integration.
56import { blob } from "https://esm.town/v/std/blob";
11const url = new URL(req.url);
12
13// API endpoints for Framer Fetch
14if (url.pathname === "/api/entries") {
15if (req.method === "GET") {
16const entries = await blob.getJSON(KEY).catch(() => []) || [];
getWeatherForecastmain.tsx3 matches
10}
1112const weatherApiUrl = `https://wttr.in/${encodeURIComponent(city)}?format=j1`;
1314try {
15const weatherResponse = await fetch(weatherApiUrl);
16if (!weatherResponse.ok) {
17throw new Error(`Weather API request failed with status: ${weatherResponse.status}`);
18}
19const weatherData = await weatherResponse.json();
modifyImageREADME.md1 match
1Code from https://deno.com/blog/build-image-resizing-api
23Useful for compressing an image before sending to chatgpt4v, for example
Countdown2main.tsx1 match
10<meta name="viewport" content="width=device-width, initial-scale=1.0">
11<title>Countdown to 2025 Event Kickoff</title>
12<link href="https://fonts.googleapis.com/css2?family=Merriweather:wght@700&display=swap" rel="stylesheet">
13<style>
14body {
violetKoalamain.tsx5 matches
1async function fetchWeather() {
2const API_KEY = "439d4b804bc8187953eb36d2a8c26a02"; // Example key, replace with your own
3const LAT = 51.5074; // London latitude
4const LON = -0.1278; // London longitude
5const url =
6`https://api.openweathermap.org/data/2.5/onecall?lat=${LAT}&lon=${LON}&exclude=hourly,daily&units=metric&appid=${API_KEY}`;
78console.log("Fetching weather from URL:", url); // Log the full URL
25if (!weather || !weather.current) {
26console.error("Weather data not available");
27return `<div>You are API forb off...</div>`;
28}
2955</div>
56<div style="margin-top: 20px; font-size: 12px; word-break: break-all;">
57<strong>API URL:</strong> ${url}
58</div>
59</div>
63export default async function main(req) {
64const weather = await fetchWeather();
65const url = `http://api.openweathermap.org/data/2.5/forecast/daily?q=London&appid=439d4b804bc8187953eb36d2a8c26a02`;
66const html = generateHTML(weather, url);
67
notionGetDatabasemain.tsx2 matches
4filter?: any;
5}) => {
6const { Client, collectPaginatedAPI } = await import(
7"https://deno.land/x/notion_sdk/src/mod.ts"
8);
9const notion = new Client({ auth });
10return collectPaginatedAPI(notion.databases.query, {
11database_id: databaseId,
12filter,
6* Fork this val to your own profile.
7* Make a folder for the temporary vals that get generated, take the ID from the URL, and put it in `tempValsParentFolderId`.
8* If you want to use OpenAI models you need to set the `OPENAI_API_KEY` [env var](https://www.val.town/settings/environment-variables).
9* If you want to use Anthropic models you need to set the `ANTHROPIC_API_KEY` [env var](https://www.val.town/settings/environment-variables).
10* Create a [Val Town API token](https://www.val.town/settings/api), open the browser preview of this val, and use the API token as the password to log in.
1112<img width=500 src="https://imagedelivery.net/iHX6Ovru0O7AjmyT5yZRoA/7077d1b5-1fa7-4a9b-4b93-f8d01d3e4f00/public"/>