Val Town Code SearchReturn to Val Town

API Access

You can access search results via JSON API by adding format=json to your query:

https://codesearch.val.run/$%7Burl%7D?q=fetch&page=685&format=json

For typeahead suggestions, use the /typeahead endpoint:

https://codesearch.val.run/typeahead?q=fetch

Returns an array of strings in format "username" or "username/projectName"

Found 9034 results for "fetch"(2038ms)

getValsContextWindowmain.tsx7 matches

@janpaul123•Updated 10 months ago
69 );
70 });
71 export default app.fetch;`,
72 },
73 {
129 {
130 prompt: "Write a val that accesses environment variables",
131 code: `const res = await fetch("${API_URL}/v1/me", {
132 headers: {
133 Authorization: \`Bearer \${Deno.env.get("valtown")}\`,
141 code: `import process from "node:process";
142
143 const res = await fetch("${API_URL}/v1/me", {
144 headers: {
145 Authorization: \`Bearer \${process.env.valtown}\`,
165 code: `import cheerio from "npm:cheerio";
166
167 const response = await fetch("https://example.com");
168 const body = await response.text();
169 const $ = cheerio.load(body);
453 {
454 role: "user",
455 content: "Write a val that fetches the weather in Brooklyn, NY",
456 },
457 {
458 role: "assistant",
459 content:
460 "```ts\nexport default async function(req: Request): Promise<Response> {\n const apiKey = Deno.env.get(\"METEO_KEY\");\n const apiUrl = `https://api.open-meteo.com/v1/forecast?latitude=40.6782&longitude=-73.9442&hourly=temperature_2m&current_weather=true&apikey=${apiKey}`;\n\n const response = await fetch(apiUrl);\n const weatherData = await response.json();\n\n return new Response(JSON.stringify(weatherData), { headers: { \"Content-Type\": \"application/json\" } });\n}\n```",
461 },
462 {
467 role: "assistant",
468 content:
469 "```ts\n/** @jsxImportSource npm:hono@3/jsx */\nimport { Hono } from \"npm:hono\";\n\nconst app = new Hono();\napp.get(\"/\", async (c) => {\n return c.html(\n <div>\n <form>\n Your name: <input type=\"text\" name=\"name\" /> <input type=\"submit\" />\n </form>\n Hello {c.req.query(\"name\")}\n </div>,\n );\n});\nexport default app.fetch;\n```",
470 },
471 ...templatePrompts,

blob_adminmain.tsx2 matches

@janpaul123•Updated 10 months ago
1/** @jsxImportSource https://esm.sh/hono@4.0.8/jsx **/
2
3import { modifyFetchHandler } from "https://esm.town/v/andreterron/codeOnValTown?v=50";
4import view_route from "https://esm.town/v/pomdtr/blob_admin_blob";
5import create_route from "https://esm.town/v/pomdtr/blob_admin_create";
133});
134
135export default modifyFetchHandler(passwordAuth(app.fetch));

valwritermain.tsx6 matches

@janpaul123•Updated 10 months ago
2import { updateValByName } from "https://esm.town/v/nbbaier/updateValByName?v=14";
3import { basicAuth } from "https://esm.town/v/pomdtr/basicAuth?v=62";
4import { fetchText } from "https://esm.town/v/stevekrouse/fetchText";
5import { chat } from "https://esm.town/v/stevekrouse/openai";
6import cronstrue from "npm:cronstrue";
19It stores each line of the poem in sqlite.
20It has a textbox that lets anyone input a new line to the poem.`,
21 content: await fetchText("https://esm.town/v/stevekrouse/poembuilder3?v=4"),
22 },
23 {
24 user: "an app that uses chatgpt to convert natural language to cron syntax",
25 content: await fetchText("https://esm.town/v/stevekrouse/cron2"),
26 },
27];
29const app = new Hono();
30
31export default basicAuth(app.fetch);
32app.get("/", async (c) => {
33 const example = examples[Math.floor(Math.random() * examples.length)];
98 Write ONLY Deno TypeScript.
99
100 If you use Hono, use \`export default app.fetch;\` to start the server.
101
102 Only use web standard fetch.
103 // Our library for SQLite
104 import { sqlite } from "https://esm.town/v/std/sqlite";

spotifymain.tsx9 matches

@hunty•Updated 10 months ago
2import { home, scopesRoute } from "https://esm.town/v/hunty/spotify_helpers";
3import { sqlite } from "https://esm.town/v/std/sqlite?v=4";
4import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
5import { querystring } from "https://esm.town/v/stevekrouse/querystring";
6import { thisWebURL } from "https://esm.town/v/stevekrouse/thisWebURL";
25
26export let spotifyRequestToken = ({ client_id, client_secret, code, redirect_uri }) =>
27 fetchJSON("https://accounts.spotify.com/api/token", {
28 method: "POST",
29 body: querystring({
39
40export let spotifyRefreshToken = async ({ refresh_token, client_id, client_secret }) =>
41 fetch("https://accounts.spotify.com/api/token", {
42 method: "POST",
43 body: new URLSearchParams({
191
192 try {
193 const currentlyPlaying = await fetch("https://api.spotify.com/v1/me/player/currently-playing", {
194 method: "GET",
195 headers: {
207
208 if (!mostRecentTrack) {
209 const recentTracks = await fetch("https://api.spotify.com/v1/me/player/recently-played", {
210 method: "GET",
211 headers: {
220 }
221 catch (e) {
222 return c.json({ error: "Fetch Error" + e }, 500);
223 }
224});
232
233 try {
234 const playStateResponse = await fetch("https://api.spotify.com/v1/me/player?market=US", {
235 method: "GET",
236 headers: {
251 }
252 catch (e) {
253 return c.json({ error: "Fetch Error" + e }, 503);
254 }
255});
256
257export default app.fetch;

dailyPoemForSammain.tsx3 matches

@iamseeley•Updated 10 months ago
1import { fetch } from "https://esm.town/v/std/fetch";
2
3async function getRandomPoem() {
4 const response = await fetch("https://poetrydb.org/random");
5 const [poem] = await response.json();
6 return poem;
16 const message = `Daily Poem:\n\n${title}\nby ${author}\n\n${lines}`;
17
18 const response = await fetch('https://samwho-notify.web.val.run', {
19 method: 'POST',
20 headers: {

urlMetadatamain.tsx1 match

@yawnxyz•Updated 10 months ago
6 return metadata;
7 } catch (err) {
8 console.error('Error fetching metadata:', err);
9 return null;
10 }

acemain.tsx1 match

@saolsen•Updated 10 months ago
99
100export default async function handler(req: Request): Promise<Response> {
101 return await app.fetch(req);
102}

notifymain.tsx2 matches

@samwho•Updated 10 months ago
1import { fetch } from "https://esm.town/v/std/fetch";
2import process from "node:process";
3
17 }
18
19 const resp = await fetch("https://api.pushover.net/1/messages.json", {
20 headers: {
21 "Content-Type": "application/json",

isMyWebsiteDownmain.tsx2 matches

@netizen•Updated 10 months ago
9 let reason: string;
10 try {
11 const res = await fetch(URL, { redirect: "follow" });
12 if (res.status !== 200) {
13 reason = `(status code: ${res.status})`;
15 }
16 } catch (e) {
17 reason = `couldn't fetch: ${e}`;
18 ok = false;
19 }

randomCardImagemain.tsx4 matches

@jamiedubs•Updated 10 months ago
1import { fetch } from "https://esm.town/v/std/fetch";
2
3export default async function(req: Request): Promise<Response> {
4 try {
5 const response = await fetch(
6 "https://deckofcardsapi.com/api/deck/new/draw/?count=1",
7 );
14 }
15 } catch (error) {
16 console.log("Error fetching random card image:", error);
17 return Response.json({
18 error: `An error occurred while fetching the random card image. ${error}`,
19 }, { status: 400 });
20 }

TAC_FetchBasic2 file matches

@A7_OMC•Updated 11 hours ago

hn-fetch1 file match

@matija•Updated 13 hours ago