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=41&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 8186 results for "fetch"(1582ms)

myeverythingmain.tsx1 match

@yassinreg•Updated 4 days ago
25
26 try {
27 const response = await fetch(window.location.href, {
28 method: "POST",
29 body: formData,

feedbackmain.tsx1 match

@yassinreg•Updated 4 days ago
25
26 try {
27 const response = await fetch(window.location.href, {
28 method: "POST",
29 body: formData,

FixItWandindex.http.ts1 match

@wolf•Updated 4 days ago
18 });
19
20export default app.fetch;

daily-advice-appmain.tsx4 matches

@dcm31•Updated 4 days ago
7 const [loading, setLoading] = useState(false);
8
9 async function fetchAdvice() {
10 setLoading(true);
11 try {
12 const res = await fetch("https://api.adviceslip.com/advice");
13 const data = await res.json();
14 setAdvice(data.slip.advice);
21
22 useEffect(() => {
23 fetchAdvice();
24 }, []);
25
32 </p>
33 <button
34 onClick={fetchAdvice}
35 className="mt-6 bg-blue-500 hover:bg-blue-600 text-white font-semibold py-2 px-4 rounded w-full"
36 disabled={loading}

mini-remixrender.tsx1 match

@probablycorey•Updated 4 days ago
56 e.preventDefault()
57 const form = e.currentTarget as HTMLFormElement
58 const res = await fetch(form.action || window.location.href, {
59 method: form.method || "POST",
60 body: new FormData(form),

moiPosterImprovedMoiEditor.tsx7 matches

@dcm31•Updated 4 days ago
8 disabled?: boolean;
9 username?: string; // Username prop to set default author
10 valId?: string; // Val ID for fetching endpoints
11 apiToken?: string; // Token for API requests
12}
62 const initializedRef = useRef(false);
63
64 // Fetch HTTP endpoints if available
65 useEffect(() => {
66 if (!valId || !apiToken) return;
67
68 const fetchEndpoints = async () => {
69 setLoadingEndpoints(true);
70 setEndpointsError(null);
71
72 try {
73 const response = await fetch(`/api/vals/${valId}/endpoints`, {
74 headers: { 'Authorization': `Bearer ${apiToken}` }
75 });
76
77 if (!response.ok) {
78 throw new Error(`Failed to fetch endpoints: ${response.statusText}`);
79 }
80
82 setEndpoints(data.endpoints || []);
83 } catch (error) {
84 console.error('Error fetching endpoints:', error);
85 setEndpointsError(error instanceof Error ? error.message : 'Unknown error');
86 } finally {
89 };
90
91 fetchEndpoints();
92 }, [valId, apiToken]);
93

moiPosterImprovedApp.tsx29 matches

@dcm31•Updated 4 days 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 4 days 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 4 days 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 5 days 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;

fetchPaginatedData2 file matches

@nbbaier•Updated 1 week ago

FetchBasic1 file match

@fredmoon•Updated 1 week ago