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/?q=fetch&page=552&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 8238 results for "fetch"(1523ms)

dotShortcutmain.tsx2 matches

@pomdtrUpdated 7 months ago
12 const [author, name] = subdomain.split("-");
13
14 const resp = await fetch(`https://api.val.town/v1/alias/${author}/${name}`);
15 if (!resp.ok) {
16 console.error("failed to fetch val infos");
17 return;
18 }

scrape2mdmain.tsx7 matches

@tarasUpdated 8 months ago
57 }
58
59 const fetch_response = await fetch(url.toString(), {
60 method: req.method,
61 headers: new Headers({
64 "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8",
65 "Accept-Language": "en-US,en;q=0.5",
66 "Sec-Fetch-Site": "cross-site",
67 "Sec-Fetch-Mode": "navigate",
68 "Sec-Fetch-User": "?1",
69 "Sec-Fetch-Dest": "document",
70 "Referer": "https://www.google.com/",
71 "sec-ch-ua": `"Not A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"`,
76 }),
77 });
78 const contentType = fetch_response.headers.get("content-type");
79 const response_text = await fetch_response.text();
80 // We only handle html, pass content through otherwise
81 if (!contentType?.includes("text/html")) {

OpenAImain.tsx1 match

@hash0000ffUpdated 8 months ago
12 * @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
13 * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
14 * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
15 * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
16 * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.

redditImageGrabmain.tsx7 matches

@yawnxyzUpdated 8 months ago
2import React, { useEffect, useState } from "https://esm.sh/react";
3import { createRoot } from "https://esm.sh/react-dom/client";
4import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
5
6const subreddits = ["IdiotsInCars"];
7
8const fetchWithImage = async (subreddit: string) => {
9 const { data: { children } } = await fetchJSON(
10 `https://www.reddit.com/r/${subreddit}.json`,
11 );
24};
25
26const fetchAllReddits = async () => {
27 const posts = (await Promise.all(subreddits.map(fetchWithImage))).flat();
28 return posts;
29};
45
46 useEffect(() => {
47 fetch("/api/posts").then(ok => ok.json())
48 .then(posts => setPosts(posts));
49 }, []);
64export default async function server(req: Request): Promise<Response> {
65 if (req.url.endsWith("/api/posts")) {
66 const posts = await fetchAllReddits();
67 posts.sort((a, b) => b.score - a.score);
68 return Response.json(posts);

lucia_honomain.tsx1 match

@saolsenUpdated 8 months ago
548 req: Request,
549): Promise<Response> {
550 return await app.fetch(req);
551}

pr0nmain.tsx7 matches

@roramigatorUpdated 8 months ago
2import React, { useEffect, useState } from "https://esm.sh/react";
3import { createRoot } from "https://esm.sh/react-dom/client";
4import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
5
6const subreddits = ["Battletops", "AverageBattlestations", "desksetup"];
7
8const fetchWithImage = async (subreddit: string) => {
9 const { data: { children } } = await fetchJSON(
10 `https://www.reddit.com/r/${subreddit}.json`,
11 );
24};
25
26const fetchAllReddits = async () => {
27 const posts = (await Promise.all(subreddits.map(fetchWithImage))).flat();
28 return posts;
29};
45
46 useEffect(() => {
47 fetch("/api/posts").then(ok => ok.json())
48 .then(posts => setPosts(posts));
49 }, []);
64export default async function server(req: Request): Promise<Response> {
65 if (req.url.endsWith("/api/posts")) {
66 const posts = await fetchAllReddits();
67 posts.sort((a, b) => b.score - a.score);
68 return Response.json(posts);

OpenAImain.tsx1 match

@arthrodUpdated 8 months ago
12 * @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
13 * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
14 * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
15 * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
16 * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.

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

fetchPaginatedData2 file matches

@nbbaierUpdated 1 week ago

FetchBasic1 file match

@fredmoonUpdated 1 week ago