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/$%7Bsuccess?q=fetch&page=645&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 9164 results for "fetch"(1581ms)

valWallmain.tsx9 matches

@iamseeleyUpdated 8 months ago
36
37async function generateGraph(username) {
38 console.log(`Fetching contributions for ${username}`);
39 try {
40 const contributionData = await fetchContributions(username);
41 const totalContributions = Object.values(contributionData).reduce((sum, count) => sum + count, 0);
42 console.log(`Total contributions: ${totalContributions}`);
56}
57
58async function fetchContributions(username) {
59 const contributionMap = {};
60 const valsUrl = `https://api.val.town/v1/alias/${username}/vals`;
61 const valsResponse = await fetch(valsUrl);
62 if (!valsResponse.ok) {
63 throw new Error(`HTTP error! status: ${valsResponse.status}`);
83 contributionMap[creationDate] = (contributionMap[creationDate] || 0) + 1;
84
85 await fetchValVersions(val.id, contributionMap, creationDate);
86 }
87 }
90}
91
92async function fetchValVersions(valId, contributionMap, creationDate) {
93 const versionsUrl = `https://api.val.town/v1/vals/${valId}/versions`;
94 try {
95 const versionsResponse = await fetch(versionsUrl);
96 if (!versionsResponse.ok) {
97 throw new Error(`HTTP ${versionsResponse.status}`);
115 }
116 } catch (error) {
117 console.error(`Failed to fetch versions for val ${valId}:`, error.message);
118 }
119}
199}
200
201export default app.fetch;

spacexapimain.tsx1 match

@moeUpdated 8 months ago
30
31async function loadPage(url) {
32 const response = await fetch(url)
33 const body = await response.text()
34 const $ = cheerio.load(body)

extremePlumCariboumain.tsx15 matches

@ejfoxUpdated 8 months ago
21 setUsername(usernameFromPath || 'ejfox'); // Default to 'ejfox' if no username provided
22
23 const fetchVals = async () => {
24 setLoading(true);
25 setVals([]);
27 setDebugInfo([]);
28 try {
29 setDebugInfo(prev => [...prev, `Fetching vals for ${usernameFromPath || 'ejfox'}...`]);
30 const response = await fetch(`/vals/${usernameFromPath || 'ejfox'}`);
31 if (!response.ok) {
32 throw new Error(`HTTP error! status: ${response.status}`);
40 }
41
42 setDebugInfo(prev => [...prev, `Fetched ${data.vals.length} vals`]);
43
44 // Fetch emojis for each val with a delay
45 for (const val of data.vals) {
46 setDebugInfo(prev => [...prev, `Fetching emoji for ${val.name}...`]);
47 const emoji = await fetchEmojiForName(val.name);
48 setVals(prevVals => [...prevVals, { ...val, emoji }]);
49 await new Promise(resolve => setTimeout(resolve, 2000)); // 2 second delay
50 }
51
52 setDebugInfo(prev => [...prev, 'All vals and emojis fetched']);
53 } catch (error) {
54 console.error('Error fetching vals:', error);
55 setError(error.toString());
56 setDebugInfo(prev => [...prev, `Error: ${error.message}`]);
60 };
61
62 fetchVals();
63 }, []);
64
119}
120
121async function fetchEmojiForName(name) {
122 try {
123 const response = await fetch(`/emoji/${encodeURIComponent(name)}`);
124 if (response.ok) {
125 const data = await response.json();
126 return data.emoji;
127 }
128 console.error('Error fetching emoji:', response.statusText);
129 } catch (error) {
130 console.error('Error fetching emoji:', error);
131 }
132 return '❓'; // Placeholder
172 for await (const val of client.users.vals.list(user.id, { limit: 100 })) {
173 vals.push(val);
174 await new Promise(resolve => setTimeout(resolve, 2000)); // 2 second delay between fetches
175 }
176

allvalsindexmain.tsx2 matches

@ejfoxUpdated 8 months ago
19
20 useEffect(() => {
21 fetch('/vals')
22 .then(response => {
23 if (!response.ok) {
39 })
40 .catch(error => {
41 console.error('Error fetching vals:', error);
42 setError(error.toString());
43 setLoading(false);

sqliteExplorerAppmain.tsx4 matches

@febUpdated 8 months ago
1/** @jsxImportSource https://esm.sh/hono@latest/jsx **/
2
3import { modifyFetchHandler } from "https://esm.town/v/andreterron/codeOnValTown?v=50";
4import { iframeHandler } from "https://esm.town/v/nbbaier/iframeHandler";
5import { resetStyle } from "https://esm.town/v/nbbaier/resetStyle";
16import { verifyToken } from "https://esm.town/v/pomdtr/verifyToken";
17import { ResultSet, sqlite } from "https://esm.town/v/std/sqlite";
18import { reloadOnSaveFetchMiddleware } from "https://esm.town/v/stevekrouse/reloadOnSave";
19import { Hono } from "npm:hono";
20import type { FC } from "npm:hono/jsx";
175});
176
177export const handler = app.fetch;
178export default iframeHandler(modifyFetchHandler(passwordAuth(handler, { verifyPassword: verifyToken })));

blob_adminmain.tsx2 matches

@snptrsUpdated 8 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";
137});
138
139export default modifyFetchHandler(passwordAuth(app.fetch));

sketchmain.tsx1 match

@ff6347Updated 8 months ago
11 const imageUrl = "https://charlypoly-httpapiscreenshotpageexample.web.val.run/?url=" + url.origin
12 // return Response.redirect(imageUrl, 302)
13 const res = await fetch(imageUrl)
14 const blob = await res.blob()
15 return new Response(blob, { headers: { "Content-Type": "image/png" } })

calculateTransitAPImain.tsx4 matches

@rochambeau314Updated 8 months ago
82 const distanceMatrixUrl = `https://maps.googleapis.com/maps/api/distancematrix/json?origins=${encodeURIComponent(origin)}&destinations=${encodeURIComponent(destinations)}&mode=driving&key=${apiKey}`;
83
84 const response = await fetch(distanceMatrixUrl);
85 const data = await response.json();
86
117 }
118
119 const directionsResponse = await fetch(directionsUrl);
120 const directionsData = await directionsResponse.json();
121
132 const directionsUrl = `https://maps.googleapis.com/maps/api/directions/json?origin=${encodeURIComponent(origin)}&destination=${encodeURIComponent(destination)}&mode=transit&key=${apiKey}`;
133
134 const directionsResponse = await fetch(directionsUrl);
135 const directionsData = await directionsResponse.json();
136
146async function getZipCode(address: string, apiKey: string): Promise<string> {
147 const geocodeUrl = `https://maps.googleapis.com/maps/api/geocode/json?address=${encodeURIComponent(address)}&key=${apiKey}`;
148 const response = await fetch(geocodeUrl);
149 const data = await response.json();
150

fluxImageGeneratormain.tsx1 match

@danyslicerUpdated 8 months ago
81 setError("");
82 try {
83 const response = await fetch("/generate", {
84 method: "POST",
85 headers: { "Content-Type": "application/json" },

weatherGPTmain.tsx1 match

@tgrvUpdated 8 months ago
4let location = "Wolfsburg";
5let lang = "de";
6const weather = await fetch(
7 `https://wttr.in/${location}?lang=${lang}&format=j1`,
8).then(r => r.json());

proxyFetch2 file matches

@vidarUpdated 20 hours ago

TAC_FetchBasic2 file matches

@A7_OMCUpdated 1 day ago