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=1&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 15666 results for "fetch"(5195ms)

aimixmain.tsx2 matches

@wizos•Updated 2 hours ago
100 }
101
102 return fetch(requestParams.url, preload).catch((err) => new Response(err.stack, { status: 500 }));
103});
104
112// app.post("/v1/chat/completions", handleChatCompletionWrap);
113
114export default app.fetch;

Sonarneynar.ts21 matches

@moe•Updated 4 hours ago
2// const baseUrl = "https://api.neynar.com/v2/farcaster/";
3
4export async function fetchNeynarGet(path: string) {
5 const res = await fetch(baseUrl + encodeURIComponent(path), {
6 method: 'GET',
7 headers: {
15}
16
17export async function fetchNeynarGetPages(path: string, pages: number, dataKey: string) {
18 let data: any = []
19 let cursor = ''
20 let pagesLeft = pages
21 while (true) {
22 const res = await fetchNeynarGet(`${path}&cursor=${cursor}`)
23 data = [...data, ...res[dataKey]]
24 cursor = res?.next?.cursor
35//////////
36
37export function fetchUser(username: string) {
38 if (username.startsWith('fid:')) {
39 return fetchUsersById(username.replace('fid:', '')).then((users) => users[0])
40 }
41 return fetchNeynarGet(`user/by_username?username=${username}`).then((r) => r.user)
42}
43export function fetchUsersById(fids: string) {
44 return fetchNeynarGet(`user/bulk?fids=${fids}`).then((r) => r.users)
45}
46
47export function fetchUserFeed(fid: string) {
48 return fetchNeynarGet(
49 `feed?feed_type=filter&filter_type=fids&fids=${fid}&with_recasts=false&with_replies=false&limit=100&cursor=`
50 ).then((r) => r.casts)
51}
52
53export function fetchChannel(channelId: string) {
54 return fetchNeynarGet(`channel?id=${channelId}`).then((r) => r.channel)
55}
56
57export function fetchChannelFeed(channelId: string) {
58 return fetchNeynarGet(`feed/channels?channel_ids=${channelId}&with_recasts=false&limit=100`).then((r) => r.casts)
59}
60
61export function fetchChannelsFeed(channelIds: string[]) {
62 return fetchNeynarGet(`feed/channels?channel_ids=${channelIds.join(',')}&with_recasts=false&limit=100`).then(
63 (r) => r.casts
64 )
65}
66
67export function fetchCast(hash: string) {
68 return fetchNeynarGet(`cast?type=hash&identifier=${hash}`).then((r) => r.cast)
69}
70
71export function fetchCastReplies(hash: string) {
72 return fetchNeynarGet(
73 `cast/conversation?identifier=${hash}&type=hash&reply_depth=2&include_chronological_parent_casts=false&sort_type=algorithmic&fold=above&limit=20`
74 ).then((r) => r?.conversation?.cast?.direct_replies)

Sonarmisc.tsx6 matches

@moe•Updated 4 hours ago
68//////////
69
70export async function fetchProxyJSON(url: string) {
71 const baseUrl = 'https://sonar.val.run/proxy?path='
72 const res = await fetch(baseUrl + encodeURIComponent(url), {
73 method: 'GET',
74 headers: { 'Content-Type': 'application/json' },
78}
79
80export async function fetchStarterPack(id: string | undefined) {
81 if (!id) return null
82 return await fetchProxyJSON(`https://client.farcaster.xyz/v2/starter-pack?id=${id}`).then(
83 (r) => r?.result?.starterPack
84 )
85}
86
87export function fetchStarterPackMemberIds(id: string) {
88 return fetch(`https://api.warpcast.com/fc/starter-pack-members?id=${id}`)
89 .then((res) => res.json())
90 .then((data) => data?.result?.members)

HTTP_exampleshonoExample1 match

@dazzag24•Updated 10 hours ago
4app.get("/", (c) => c.text("Hello from Hono!"));
5app.get("/yeah", (c) => c.text("Routing!"));
6export default app.fetch;

HTTP_examplesfetsExample1 match

@dazzag24•Updated 10 hours ago
21});
22
23export default router.fetch;

funmain.tsx10 matches

@join•Updated 15 hours ago
215 };
216
217 const fetchMessages = async (retries = 3, delay = 1000) => {
218 try {
219 const response = await fetch('/messages');
220 if (!response.ok) {
221 const errorData = await response.json().catch(() => ({}));
227 console.error(error);
228 if (retries > 0) {
229 setTimeout(() => fetchMessages(retries - 1, delay * 2), delay);
230 } else {
231 showStatus('Could not load community messages. ' + error.message, 'error');
246
247 try {
248 const response = await fetch('/submit', {
249 method: 'POST',
250 headers: { 'Content-Type': 'application/json' },
260 showStatus('Vibe approved! Your message is live.', 'success');
261 form.reset();
262 fetchMessages();
263
264 } catch (error) {
272
273 // Initial load
274 fetchMessages();
275})();
276</script>
289});
290
291// Route to fetch all approved messages
292app.get("/messages", async (c) => {
293 try {
295 return c.json(messages);
296 } catch (error) {
297 console.error("Failed to fetch messages from blob:", error);
298 return c.json({ error: "Error fetching messages." }, 500);
299 }
300});
361});
362
363export default app.fetch;

reactHonoStarterindex.ts2 matches

@baranerdogan•Updated 15 hours ago
21});
22
23// HTTP vals expect an exported "fetch handler"
24// This is how you "run the server" in Val Town with Hono
25export default app.fetch;
133 const auth = btoa(`${REDDIT_CLIENT_ID}:${REDDIT_CLIENT_SECRET}`);
134
135 const response = await fetch("https://www.reddit.com/api/v1/access_token", {
136 method: "POST",
137 headers: {
163
164/**
165 * Fetches recent posts from a subreddit using Reddit API
166 */
167async function fetchSubredditPostsAPI(subreddit: string, limit: number = 25): Promise<RedditPost[]> {
168 try {
169 const accessToken = await getRedditAccessToken();
170 const url = `https://oauth.reddit.com/r/${subreddit}/new?limit=${limit}`;
171
172 const response = await fetch(url, {
173 headers: {
174 "Authorization": `Bearer ${accessToken}`,
184 return data.data.children.map(child => child.data);
185 } catch (error) {
186 console.error(`Error fetching posts from r/${subreddit} via API:`, error);
187 throw error;
188 }
190
191/**
192 * Fallback: Fetches recent posts using Reddit's JSON endpoint
193 */
194async function fetchSubredditPostsJSON(subreddit: string, limit: number = 25): Promise<RedditPost[]> {
195 try {
196 const url = `https://www.reddit.com/r/${subreddit}/new.json?limit=${limit}`;
197
198 const response = await fetch(url, {
199 headers: {
200 "User-Agent": "Mozilla/5.0 (compatible; UnifiedRedditMonitor/1.0; +https://val.town)",
212 return data.data.children.map(child => child.data);
213 } catch (error) {
214 console.error(`Error fetching posts from r/${subreddit} via JSON:`, error);
215 throw error;
216 }
295
296/**
297 * Fallback: Fetches RSS feed from a subreddit and converts to RedditPost format
298 */
299async function fetchSubredditPostsRSS(subreddit: string): Promise<RedditPost[]> {
300 try {
301 const url = `https://www.reddit.com/r/${subreddit}/new.rss`;
302
303 const response = await fetch(url, {
304 headers: {
305 "User-Agent": "Mozilla/5.0 (compatible; UnifiedRedditMonitor/1.0; +https://val.town)",
330 }));
331 } catch (error) {
332 console.error(`Error fetching RSS from r/${subreddit}:`, error);
333 throw error;
334 }
336
337/**
338 * Fetches posts from a subreddit with fallback methods
339 */
340async function fetchSubredditPosts(subreddit: string, limit: number = 25): Promise<RedditPost[]> {
341 // Try API first
342 try {
343 console.log(` šŸ“” Trying Reddit API for r/${subreddit}...`);
344 return await fetchSubredditPostsAPI(subreddit, limit);
345 } catch (apiError) {
346 console.log(` āš ļø API failed for r/${subreddit}, trying JSON endpoint...`);
348 // Try JSON endpoint
349 try {
350 return await fetchSubredditPostsJSON(subreddit, limit);
351 } catch (jsonError) {
352 console.log(` āš ļø JSON failed for r/${subreddit}, trying RSS...`);
354 // Try RSS as last resort
355 try {
356 return await fetchSubredditPostsRSS(subreddit);
357 } catch (rssError) {
358 console.error(` āŒ All methods failed for r/${subreddit}`);
359 throw new Error(
360 `All fetch methods failed for r/${subreddit}: API(${apiError.message}), JSON(${jsonError.message}), RSS(${rssError.message})`,
361 );
362 }
438 };
439
440 const response = await fetch(SLACK_WEBHOOK_URL, {
441 method: "POST",
442 headers: {
515
516 try {
517 const response = await fetch(`${SUPABASE_URL}/rest/v1/relevant_reddit_posts`, {
518 method: "POST",
519 headers: {
564 if (CONFIG.useSlack) {
565 try {
566 await fetch(SLACK_WEBHOOK_URL, {
567 method: "POST",
568 headers: {
689
690 try {
691 // Fetch recent posts from this subreddit (with fallback methods)
692 const posts = await fetchSubredditPosts(subreddit, CONFIG.postLimit);
693 console.log(` āœ… Fetched ${posts.length} posts from r/${subreddit}`);
694 totalPosts += posts.length;
695
724
725 console.log(`\nšŸ“Š Final Summary:`);
726 console.log(`šŸ“„ Total posts fetched: ${totalPosts}`);
727 console.log(`šŸ†• Total new posts: ${totalNewPosts}`);
728 console.log(`āœ… Total matches found: ${allMatchingPosts.length}`);

CronURLmain.tsx1 match

@balloon•Updated 16 hours ago
3export async function cronUrl(url: string) {
4 try {
5 const res = await fetch(url);
6 console.log(`${url} ${res.status} `);
7 } catch (e) {

TownieuseUser.tsx4 matches

@chetanshi29•Updated 19 hours ago
8 const [error, setError] = useState(null);
9
10 const fetchData = async () => {
11 try {
12 const userEndpoint = new URL(USER_ENDPOINT, window.location.origin);
13
14 const res = await fetch(userEndpoint);
15 const data = await res.json();
16 if (!res.ok) {
33
34 useEffect(() => {
35 fetchData();
36 }, []);
37
38 return { data, loading, error, refetch: fetchData };
39}
40

manual-fetcher

@miz•Updated 3 days ago

fake-https1 file match

@blazemcworld•Updated 1 week ago
simple proxy to fetch http urls using https