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/%7Bresult.originalUrl%7D?q=fetch&page=10&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 19093 results for "fetch"(890ms)

TownieCreditBalance.tsx5 matches

@Skywalker•Updated 4 hours ago
7 const [loading, setLoading] = useState(true);
8
9 const fetchBalance = async () => {
10 try {
11 const response = await fetch("/api/credit-balance");
12 if (response.ok) {
13 const data = await response.json();
15 setBalance(data.balance);
16 } else {
17 console.error("Failed to fetch balance");
18 }
19 } catch (err) {
20 console.error("Error fetching balance:", err);
21 } finally {
22 setLoading(false);
25
26 useEffect(() => {
27 fetchBalance();
28 }, []);
29

TownieChatRouteSingleColumn.tsx13 matches

@Skywalker•Updated 4 hours ago
51 files={project.data?.files}
52 branchId={branchId}
53 refetch={project.refetch}
54 />
55 </ProjectContext.Provider>
61 files,
62 branchId,
63 refetch,
64}: {
65 project: any;
66 files: any[];
67 branchId: string;
68 refetch: () => void;
69}) {
70 const [images, setImages] = useState<(string|null)[]>([]);
71 const [selectedFiles, setSelectedFiles] = useState<string[]>([]);
72 const { audio, user } = useContext(AppContext);
73 const { balance, loading: balanceLoading, refetch: refetchBalance } = useCreditBalance();
74
75 const {
94 useLoadingFavicon(running);
95
96 // Track when requests end and refetch balance
97 const prevRunning = useRef(running);
98 useEffect(() => {
99 // If running changed from true to false, request just ended
100 if (prevRunning.current === true && running === false) {
101 refetchBalance();
102 }
103 prevRunning.current = running;
104 }, [running, refetchBalance]);
105
106 // Auto-poll balance every 4 seconds when credits are insufficient
110 if (hasInsufficientCredits) {
111 const intervalId = setInterval(() => {
112 refetchBalance();
113 }, 4000); // 4 seconds
114
115 return () => clearInterval(intervalId);
116 }
117 }, [balanceLoading, balance, refetchBalance]);
118
119 useEffect(() => {
120 if (!messages?.length) return;
121 let last = messages.at(-1);
122 if (shouldRefetch(last)) {
123 refetch();
124 }
125 }, [messages]);
196 <button
197 onClick={() => {
198 refetchBalance();
199 }}
200 className="icon-button"
227}
228
229function shouldRefetch (message) {
230 for (let i = 0; i < message?.parts?.length; i++) {
231 let part = message.parts[i];

TownieBranchSelect.tsx1 match

@Skywalker•Updated 4 hours ago
32 return;
33 }
34 branches.refetch();
35 if (res?.branch?.id) {
36 navigate(`/chat/${projectId}/branch/${res.branch.id}`);

vtEditorFilesAGENTS.md3 matches

@jrmann100•Updated 6 hours ago
239
240 // Inject data to avoid extra round-trips
241 const initialData = await fetchInitialData();
242 const dataScript = `<script>
243 window.__INITIAL_DATA__ = ${JSON.stringify(initialData)};
286
2875. **API Design:**
288 - `fetch` handler is the entry point for HTTP vals
289 - Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`
290
291

untitled-8651main.ts1 match

@dhanushsuvarna•Updated 6 hours ago
30});
31
32export default app.fetch;

spotymain.ts3 matches

@skirtowner•Updated 8 hours ago
19 const now = Date.now();
20 if (!cached.accessToken || now >= cached.expiresAt) {
21 const tokenResp = await fetch("https://accounts.spotify.com/api/token", {
22 method: "POST",
23 headers: {
49
50 while (nextUrl) {
51 const resp = await fetch(nextUrl, {
52 headers: { Authorization: `Bearer ${accessToken}` },
53 });
54 if (!resp.ok) {
55 const text = await resp.text();
56 return new Response("Failed to fetch playlists: " + text, {
57 status: 500,
58 });

untitled-7644new-file-7315.ts2 matches

@coolmoves•Updated 8 hours ago
1export default async function (interval: Interval) {
2 const f = await fetch("https://sih-2025-demo.onrender.com/");
3 const s = await f.text();
4 console.log(s);
5 const r = await fetch("https://sih-2025-demo.onrender.com/");
6 const p = await r.text();
7 console.log(p);

HTTP-Statusmain.ts1 match

@emarref•Updated 8 hours ago
13 return new Response(`${status}`, { status });
14});
15export default app.fetch;
46
47**Content-Type Support**:
48- `application/json` - Standard fetch requests
49- `text/plain` - sendBeacon requests (automatically parsed as JSON)
50
197// 500 - Server Error
198{
199 error: "Failed to fetch page data",
200 details: "Notion API error message"
201}
19
20### `useGlimpseData.ts`
21Manages glimpse data fetching and state.
22
23**Parameters:**
24- `glimpseId` - ID of the glimpse to fetch
25- `initialData` - Optional initial data to avoid refetching
26
27**Returns:** `UseGlimpseDataReturn`
29- `loading` - Loading state
30- `error` - Error state
31- `refetch` - Function to manually refetch data
32
33**Usage:**
34```typescript
35const { data, loading, error, refetch } = useGlimpseData(glimpseId, initialData);
36```
37
38### `useAgentData.ts`
39Manages agent data fetching with automatic polling.
40
41**Parameters:**
68**Session Tracking:**
69- Uses `sendBeacon` API for reliable session ending during page unload
70- Falls back to synchronous fetch if sendBeacon fails
71- Handles both normal component unmount and browser tab closure
72

FetchBasic2 file matches

@bengold•Updated 2 weeks ago

fetch1 file match

@raify•Updated 2 weeks ago