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/image-url.jpg?q=fetch&page=124&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 9530 results for "fetch"(655ms)

glastonewsindex.ts29 matches

@bensomething•Updated 1 week ago
1import fetch from "npm:node-fetch";
2import process from "node:process";
3import { BskyAgent } from "npm:@atproto/api";
8});
9
10// ======= Fetch HTML with Improved Retry =======
11async function fetchHtmlWithRetry(url, options = {}, retries = 5, delay = 1000) {
12 for (let i = 0; i < retries; i++) {
13 try {
15 const timeoutId = setTimeout(() => controller.abort(), 15000);
16
17 const response = await fetch(url, {
18 ...options,
19 signal: controller.signal,
28
29 if (!response.ok) {
30 throw new Error(`Failed to fetch: ${response.statusText}`);
31 }
32
39 if (isPrematureClose && i < retries - 1) {
40 console.warn(
41 `Fetch attempt ${i + 1} failed during .text() with "Premature close". Retrying immediately...`,
42 );
43 continue;
44 } else if (i < retries - 1) {
45 console.warn(
46 `Fetch attempt ${i + 1} failed during .text(). Retrying in ${delay}ms...`,
47 );
48 await new Promise((resolve) => setTimeout(resolve, delay));
57 if (isPrematureClose && i < retries - 1) {
58 console.warn(
59 `Fetch attempt ${i + 1} failed with "Premature close". Retrying immediately...`,
60 );
61 continue;
62 } else if (i < retries - 1) {
63 console.warn(`Fetch attempt ${i + 1} failed. Retrying in ${delay}ms...`);
64 await new Promise((resolve) => setTimeout(resolve, delay));
65 } else {
70}
71
72// ======= Fetch News =======
73async function fetchNews() {
74 const url = "https://glastonburyfestivals.co.uk/news/";
75 try {
76 const html = await fetchHtmlWithRetry(url);
77 const $ = cheerio.load(html);
78
88 return news;
89 } catch (error) {
90 console.error("Error fetching news:", error);
91 throw error;
92 }
93}
94
95// ======= Fetch Your Own Recent Bluesky Post Titles =======
96async function fetchOwnRecentPostTitles(agent, handle, limit = 100) {
97 const feed = await agent.getAuthorFeed({ actor: handle, limit });
98 return feed.data.feed.map(item => item.post.record.text);
99}
100
101// ======= Fetch Embed Data =======
102async function fetchEmbedData(url) {
103 try {
104 const html = await fetchHtmlWithRetry(url);
105 const $ = cheerio.load(html);
106
116 imageUrl = new URL(imageUrl, url).href;
117 }
118 console.log("Fetching image for URL:", imageUrl);
119
120 // For images, use the original fetchWithRetry (no .text() call)
121 const imgResponse = await fetchHtmlWithRetry(imageUrl);
122 // However, for images, we need the raw bytes, so use fetchWithRetry as before:
123 const imgResponseRaw = await fetch(imageUrl, {
124 headers: {
125 "User-Agent": "Mozilla/5.0 (compatible; MyNewsBot/1.0; +https://yourdomain.example/contact)",
162 };
163 } catch (error) {
164 console.error("Error fetching embed data:", error);
165 return null;
166 }
177
178 const myHandle = process.env.BLUESKY_USERNAME; // e.g. "yourname.bsky.social"
179 const postedTitlesArr = await fetchOwnRecentPostTitles(agent, myHandle, 100);
180 const postedTitles = new Set(postedTitlesArr);
181
182 const newsItems = await fetchNews();
183 console.log(`Fetched ${newsItems.length} news items.`);
184
185 // Find all news items not yet posted, in chronological order (oldest first)
190 console.log(`Attempting to post new news: ${latestNews.title}`);
191
192 const embedData = await fetchEmbedData(latestNews.link);
193 if (!embedData) {
194 console.error("Failed to fetch embed data. Skipping post.");
195 continue;
196 }

templateTwitterAlertmain.tsx1 match

@noumanshakeel82•Updated 1 week ago
19 : Math.floor((Date.now() - 2 * 24 * 60 * 60 * 1000) / 1000);
20
21 // Fetch and log tweets
22 const response = await socialDataSearch(`${query} since_time:${timeFrame}`);
23 console.log("Response from socialDataSearch:", response);

testtownieindex.ts1 match

@charmaine•Updated 1 week ago
39
40// Export the Hono app for HTTP val
41export default app.fetch;

testtownieindex.tsx8 matches

@charmaine•Updated 1 week ago
35
36 React.useEffect(() => {
37 async function fetchPosts() {
38 try {
39 const response = await fetch('/api/posts');
40 if (!response.ok) {
41 throw new Error('Failed to fetch posts');
42 }
43 const data = await response.json();
51 }
52
53 fetchPosts();
54 }, []);
55
82
83 React.useEffect(() => {
84 async function fetchPost() {
85 if (!slug) return;
86
87 try {
88 const response = await fetch(`/api/posts/${slug}`);
89 if (response.status === 404) {
90 navigate('/not-found');
92 }
93 if (!response.ok) {
94 throw new Error('Failed to fetch post');
95 }
96 const data = await response.json();
104 }
105
106 fetchPost();
107 }, [slug, navigate]);
108

testtownieposts.ts6 matches

@charmaine•Updated 1 week ago
18 return c.json(response);
19 } catch (error) {
20 console.error("Error fetching posts:", error);
21 return c.json({ error: "Failed to fetch posts" }, 500);
22 }
23});
38 return c.json(response);
39 } catch (error) {
40 console.error("Error fetching post:", error);
41 return c.json({ error: "Failed to fetch post" }, 500);
42 }
43});
52 return c.json(response);
53 } catch (error) {
54 console.error("Error fetching tags:", error);
55 return c.json({ error: "Failed to fetch tags" }, 500);
56 }
57});
413 // Update todo status
414 try {
415 const response = await fetch('/api/todos/' + todoId, {
416 method: 'PUT',
417 headers: {
671 try {
672 // Submit log data
673 const response = await fetch('/api/log', {
674 method: 'POST',
675 headers: {

nameSeeingServermain.tsx3 matches

@SimeonL•Updated 1 week ago
18 -H 'sec-ch-ua-mobile: ?0' \
19 -H 'sec-ch-ua-platform: "macOS"' \
20 -H 'sec-fetch-dest: empty' \
21 -H 'sec-fetch-mode: cors' \
22 -H 'sec-fetch-site: same-site' \
23 -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36'
24

CareerCoach20Dayindex.ts1 match

@prashamtrivedi•Updated 1 week ago
5 * Serves the Hono application with routes for dashboard, logs, todos, and leads
6 */
7export default app.fetch
8

aqiutils.ts3 matches

@pepicrft•Updated 1 week ago
1import { blob } from "https://esm.town/v/std/blob?v=12";
2import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
3import { msDay } from "https://esm.town/v/stevekrouse/msDay";
4import { msHour } from "https://esm.town/v/stevekrouse/msHour";
25 lon: number;
26}) => {
27 const { results } = await fetchJSON(
28 `${BASE_URL}/v3/locations?`
29 + new URLSearchParams({
50export async function openAqNowcastAQI(location) {
51 const sensorID = location.sensors.find(s => s.parameter.name === "pm25").id;
52 const data = await fetchJSON(
53 `${BASE_URL}/v3/sensors/${sensorID}/measurements?`
54 + new URLSearchParams({

aqiproxy.ts1 match

@pepicrft•Updated 1 week ago
3export default async function(req: Request): Promise<Response> {
4 const url = new URL(req.url);
5 return fetch(TARGET_URL + url.pathname + url.search, {
6 headers: {
7 "X-API-Key": Deno.env.get("OpenAQ_API_KEY") as string,

agentplex-deal-flow-email-fetch1 file match

@anandvc•Updated 9 hours ago

proxyFetch2 file matches

@vidar•Updated 2 days ago