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=88&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 8587 results for "fetch"(1019ms)

blob_adminapp.tsx22 matches

@stevekrouse•Updated 1 week ago
231 const [isDragging, setIsDragging] = useState(false);
232
233 const fetchBlobs = useCallback(async () => {
234 setLoading(true);
235 try {
236 const response = await fetch(`/api/blobs?prefix=${encodeKey(searchPrefix)}&limit=${limit}`);
237 const data = await response.json();
238 setBlobs(data);
239 } catch (error) {
240 console.error("Error fetching blobs:", error);
241 } finally {
242 setLoading(false);
245
246 useEffect(() => {
247 fetchBlobs();
248 }, [fetchBlobs]);
249
250 const handleSearch = (e) => {
261 setBlobContentLoading(true);
262 try {
263 const response = await fetch(`/api/blob?key=${encodeKey(clickedBlob.key)}`);
264 const content = await response.text();
265 setSelectedBlob({ ...clickedBlob, key: decodeKey(clickedBlob.key) });
266 setEditContent(content);
267 } catch (error) {
268 console.error("Error fetching blob content:", error);
269 } finally {
270 setBlobContentLoading(false);
275 const handleSave = async () => {
276 try {
277 await fetch(`/api/blob?key=${encodeKey(selectedBlob.key)}`, {
278 method: "PUT",
279 body: editContent,
287 const handleDelete = async (key) => {
288 try {
289 await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
290 setBlobs(blobs.filter(b => b.key !== key));
291 if (selectedBlob && selectedBlob.key === key) {
304 const key = `${searchPrefix}${file.name}`;
305 formData.append("key", encodeKey(key));
306 await fetch("/api/blob", { method: "POST", body: formData });
307 const newBlob = { key, size: file.size, lastModified: new Date().toISOString() };
308 setBlobs([newBlob, ...blobs]);
312 }
313 }
314 fetchBlobs();
315 };
316
326 try {
327 const fullKey = `${searchPrefix}${key}`;
328 await fetch(`/api/blob?key=${encodeKey(fullKey)}`, {
329 method: "PUT",
330 body: "",
341 const handleDownload = async (key) => {
342 try {
343 const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
344 const blob = await response.blob();
345 const url = window.URL.createObjectURL(blob);
360 if (newKey && newKey !== oldKey) {
361 try {
362 const response = await fetch(`/api/blob?key=${encodeKey(oldKey)}`);
363 const content = await response.blob();
364 await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
365 method: "PUT",
366 body: content,
367 });
368 await fetch(`/api/blob?key=${encodeKey(oldKey)}`, { method: "DELETE" });
369 setBlobs(blobs.map(b => b.key === oldKey ? { ...b, key: newKey } : b));
370 if (selectedBlob && selectedBlob.key === oldKey) {
380 const newKey = `__public/${key}`;
381 try {
382 const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
383 const content = await response.blob();
384 await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
385 method: "PUT",
386 body: content,
387 });
388 await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
389 setBlobs(blobs.map(b => b.key === key ? { ...b, key: newKey } : b));
390 if (selectedBlob && selectedBlob.key === key) {
399 const newKey = key.slice(9); // Remove "__public/" prefix
400 try {
401 const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
402 const content = await response.blob();
403 await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
404 method: "PUT",
405 body: content,
406 });
407 await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
408 setBlobs(blobs.map(b => b.key === key ? { ...b, key: newKey } : b));
409 if (selectedBlob && selectedBlob.key === key) {

blob_adminmain.tsx1 match

@stevekrouse•Updated 1 week ago
199});
200
201export default lastlogin((request: Request) => app.fetch(request));

storymain.tsx4 matches

@Get•Updated 1 week ago
9import { OpenAI } from "https://esm.town/v/std/openai";
10// Import Request and Response types if needed (usually available globally in Val Town)
11// Example: import { Request, Response } from "https://esm.town/v/std/fetch";
12
13// --- Define Expected Data Structures ---
56
57// --- OpenAI Generation Function ---
58// Asynchronously fetches race data from OpenAI's Chat Completion API.
59async function generateRaceDataWithOpenAI(): Promise<RaceInfo[]> {
60 // Initialize the OpenAI client (using API key from Val Town secrets)
152 } catch (error) {
153 // Log the specific error encountered during the OpenAI call or processing
154 console.error("Error fetching or processing data from OpenAI:", error);
155 // Check if the error is specifically an AuthenticationError
156 if (error.constructor.name === "AuthenticationError") {
176// This function handles incoming HTTP requests and returns the HTML for the game.
177export default async function server(request: Request): Promise<Response> {
178 // 1. Fetch Race Data: Attempt to get dynamic data from OpenAI, use fallback on error.
179 const activeRaceData = await generateRaceDataWithOpenAI();
180
cerebras_coder

cerebras_coderindex.ts1 match

@Parvezalam6•Updated 1 week ago
181
182 try {
183 const response = await fetch("/", {
184 method: "POST",
185 body: JSON.stringify({

guidemain.tsx3 matches

@Get•Updated 1 week ago
59
60// --- OpenAI Generation Function ---
61// Asynchronously fetches race data from OpenAI's Chat Completion API.
62async function generateRaceDataWithOpenAI(): Promise<RaceInfo[]> {
63 // Initialize the OpenAI client (using API key from Val Town secrets)
137 return generatedData;
138 } catch (error) {
139 console.error("Error fetching or processing data from OpenAI:", error);
140 console.warn("Using fallback race data due to the error.");
141 return fallbackRaceData; // Return default data on any failure
146// This function handles incoming HTTP requests and returns an HTML response.
147export default async function server(request: Request): Promise<Response> {
148 // 1. Fetch Race Data: Attempt to get dynamic data from OpenAI, use fallback on error.
149 const activeRaceData = await generateRaceDataWithOpenAI();
150

beeminderGoalsDueTodaymain.tsx4 matches

@daryase•Updated 1 week ago
8
9 try {
10 // Fetch goals with a more detailed request
11 const goalsResponse = await fetch(
12 `https://www.beeminder.com/api/v1/users/me/goals.json?auth_token=${beeminderAuthToken}&datapoints=recent`,
13 );
14
15 if (!goalsResponse.ok) {
16 return new Response("Failed to fetch Beeminder goals", { status: goalsResponse.status });
17 }
18
44 });
45 } catch (error) {
46 return new Response(`Error fetching Beeminder goals: ${error.message}`, { status: 500 });
47 }
48}

reactHonoStarterindex.ts2 matches

@bradnoble•Updated 1 week 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;

beeminderGoalsDueTodayREADME.md1 match

@daryase•Updated 1 week ago
42and it just got those right first thing.
43
44fwiw, I'm not 100% certain it actually referenced the beeminder API docs by fetching them from the url I provided, or if it just got it somehow from having seen enough examples.
45
46## Future ideas

politymain.tsx1 match

@salon•Updated 1 week ago
786
787 // Post to the same endpoint, but add format=json and use POST with body
788 const response = await fetch(window.location.pathname + "?format=json", {
789 method: "POST",
790 headers: {

faithfulTanEelmain.tsx1 match

@salon•Updated 1 week ago
109 return generatedData;
110 } catch (error) {
111 console.error("Error fetching or processing data from OpenAI:", error);
112 console.warn("Using fallback race data due to error.");
113 return fallbackRaceData;

fetchPaginatedData2 file matches

@nbbaier•Updated 2 weeks ago

FetchBasic1 file match

@fredmoon•Updated 2 weeks ago