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/$%7Bart_info.art.src%7D?q=fetch&page=80&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 8568 results for "fetch"(726ms)

moiPosterImprovedApp.tsx29 matches

@dcm31•Updated 1 week ago
34 const [tokenError, setTokenError] = useState<string | null>(null);
35 const [username, setUsername] = useState<string>("");
36 // Flag to track if we've already tried to fetch data
37 const [initialFetchDone, setInitialFetchDone] = useState(false);
38 // Editor key for forcing re-render
39 const [editorKey, setEditorKey] = useState<string>("editor-0");
57 }, [apiToken]);
58
59 // Fetch user information to get username
60 const fetchUserInfo = useCallback(async () => {
61 if (!apiToken) return;
62
63 try {
64 const response = await fetch(`/api/user`, {
65 headers: { "Authorization": `Bearer ${apiToken}` },
66 });
74 }
75 } catch (error) {
76 console.warn("Could not fetch user info:", error);
77 // Non-critical error, don't show to user
78 }
79 }, [apiToken]);
80
81 const fetchVals = useCallback(async () => {
82 if (!apiToken) {
83 setError("Val Town API Key is required to list your vals.");
84 setLoading(false);
85 setVals([]);
86 setInitialFetchDone(true);
87 return;
88 }
97 try {
98 const queryParams = filterPrivacy !== "all" ? `?privacy=${filterPrivacy}` : "";
99 const response = await fetch(`/api/vals${queryParams}`, {
100 headers: { "Authorization": `Bearer ${apiToken}` },
101 });
108 setVals([]);
109 } else {
110 setError(`Failed to fetch vals: ${errorData.error || response.statusText}`);
111 }
112 throw new Error(`Failed to fetch vals (Status: ${response.status})`);
113 }
114 const data = await response.json();
121 }
122 } catch (err) {
123 console.error(`Error fetching vals:`, err);
124 if (!error && !tokenError) {
125 setError(`Failed to load vals. Please try again later.`);
127 } finally {
128 setLoading(false);
129 setInitialFetchDone(true);
130 }
131 }, [apiToken, filterPrivacy, initialFetchDone, error, tokenError]);
132
133 // Run initial fetch only once when API token is available
134 useEffect(() => {
135 if (apiToken && !initialFetchDone && !loading) {
136 fetchUserInfo();
137 fetchVals();
138 }
139 }, [apiToken, initialFetchDone, loading, fetchUserInfo, fetchVals]);
140
141 const handleValSelect = async (val: Val) => {
165 try {
166 const valId = val.id;
167 const response = await fetch(`/api/vals/${valId}/moi`);
168 if (!response.ok) {
169 const errorData = await response.json().catch(() => ({ error: `HTTP error ${response.status}` }));
170 throw new Error(errorData.error || "Failed to fetch moi.md");
171 }
172 const data: MoiFile = await response.json();
179 pendingSaveContentRef.current = initialContent;
180 } catch (err) {
181 console.error("Error fetching moi.md:", err);
182 setItemError(`Failed to fetch moi.md content: ${err instanceof Error ? err.message : String(err)}`);
183 if (selectedVal) {
184 const defaultContent = generateDefaultMoiContent(selectedVal);
274 console.log("Updating existing moi.md file");
275 // Update existing moi.md file using the current API endpoint
276 const response = await fetch(`/api/vals/${valId}/moi`, {
277 method: "POST",
278 headers: { "Content-Type": "application/json", "Authorization": `Bearer ${apiToken}` },
296 console.log("Creating new moi.md file");
297 // Create new moi.md file for vals that don't have one yet
298 const response = await fetch(`/api/vals/${valId}/file`, {
299 method: "POST",
300 headers: { "Content-Type": "application/json", "Authorization": `Bearer ${apiToken}` },
327
328 // Refresh the vals list to show updated status
329 fetchVals();
330
331 setTimeout(() => setSaveSuccess(false), 3000);
351 setApiToken(newToken);
352
353 // Reset the initialFetchDone flag if the token changes
354 if (newToken !== apiToken) {
355 setInitialFetchDone(false);
356 }
357 };
443 {/* Refresh Button: Aqua background, Black text */}
444 <button
445 onClick={fetchVals}
446 disabled={loading || !apiToken}
447 className={`px-3 py-1.5 rounded-md text-sm transition-colors text-[#000000] ${

moiPosterImprovedQuickEditor.tsx5 matches

@dcm31•Updated 1 week ago
142 }, [username, metadata.author, loaded]);
143
144 // Fetch the actual username from the API if we have a valId
145 useEffect(() => {
146 if (!valId || !apiToken || metadata.author) return;
147
148 const fetchUsername = async () => {
149 try {
150 const response = await fetch(`/api/username/${username}`, {
151 headers: { 'Authorization': `Bearer ${apiToken}` }
152 });
162 }
163 } catch (error) {
164 console.warn('Error fetching username:', error);
165 }
166 };
167
168 if (username) {
169 fetchUsername();
170 }
171 }, [valId, apiToken, username, metadata.author]);

speechmain.tsx1 match

@salon•Updated 1 week ago
213 try {
214 // ---- START: Replace this block in Val Town ----
215 const response = await fetch("https://api.openai.com/v1/chat/completions", {
216 method: "POST",
217 headers: {

claudeCodeLoaderindex.tsx2 matches

@matthamlin•Updated 1 week ago
25});
26
27// HTTP vals expect an exported "fetch handler"
28// This is how you "run the server" in Val Town with Hono
29export default app.fetch;

FixItWandgenerate.ts1 match

@wolf•Updated 1 week ago
34 // Only transcribe the audio if it's provided
35 if (audioB64) {
36 const audioResponse = await fetch(audioB64);
37 const audioBlob = await audioResponse.blob();
38

MiniAppStarterneynar.ts14 matches

@jhonceth•Updated 1 week ago
1const baseUrl = "https://api.neynar.com/v2/farcaster/";
2
3export async function fetchNeynarGet(path: string) {
4 const res = await fetch(baseUrl + path, {
5 method: "GET",
6 headers: {
14}
15
16export function fetchUser(username: string) {
17 return fetchNeynarGet(`user/by_username?username=${username}`).then(r => r.user);
18}
19export function fetchUsersById(fids: string) {
20 return fetchNeynarGet(`user/bulk?fids=${fids}`).then(r => r.users);
21}
22
23export function fetchUserFeed(fid: number) {
24 return fetchNeynarGet(
25 `feed?feed_type=filter&filter_type=fids&fids=${fid}&with_recasts=false&with_replies=false&limit=100&cursor=`,
26 ).then(r => r.casts);
27}
28
29export function fetchChannel(channelId: string) {
30 return fetchNeynarGet(`channel?id=${channelId}`).then(r => r.channel);
31}
32
33export function fetchChannelFeed(channelId: string) {
34 return fetchNeynarGet(
35 `feed/channels?channel_ids=${channelId}&with_recasts=false&limit=100`,
36 ).then(r => r.casts);
37}
38
39export function fetchChannelsFeed(channelIds: array) {
40 return fetchNeynarGet(
41 `feed/channels?channel_ids=${channelIds.join(",")}&with_recasts=false&limit=100`,
42 ).then(r => r.casts);

MiniAppStarterindex.tsx2 matches

@jhonceth•Updated 1 week ago
63});
64
65// HTTP vals expect an exported "fetch handler"
66// This is how you "run the server" in Val Town with Hono
67export default app.fetch;

MiniAppStarterimage.tsx2 matches

@jhonceth•Updated 1 week ago
75 const fontPromises = fontsConfig.map(async (font) => {
76 const fontUrl = "https://cdn.jsdelivr.net/npm/@tamagui/font-inter@1.108.3/otf/" + font.fontFile;
77 const fontArrayBuf = await fetch(fontUrl).then((res) => res.arrayBuffer());
78 return { name: font.name, data: fontArrayBuf, weight: font.weight };
79 });
86 // const api = `https://cdnjs.cloudflare.com/ajax/libs/twemoji/14.0.2/svg/${code.toLowerCase()}.svg`
87 const api = `https://cdn.jsdelivr.net/gh/shuding/fluentui-emoji-unicode/assets/${code.toLowerCase()}_color.svg`;
88 return fetch(api).then((r) => r.text());
89};
90

MiniAppStarterHome.tsx1 match

@jhonceth•Updated 1 week ago
7
8import { Button, Input, Section } from "../components/ui.tsx";
9import { fetchUsersById } from "../util/neynar.ts";
10
11export function Home() {
41
42async function sendNotification(notificationDetails: any, payload: any) {
43 return await fetch(notificationDetails.url, {
44 method: "POST",
45 headers: { "Content-Type": "application/json" },

fetchPaginatedData2 file matches

@nbbaier•Updated 2 weeks ago

FetchBasic1 file match

@fredmoon•Updated 2 weeks ago