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/image-url.jpg%20%22Image%20title%22?q=fetch&page=685&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 9416 results for "fetch"(2166ms)

untitled_azureWhippetmain.tsx4 matches

@jordonezrodri2•Updated 8 months ago
1import { email } from "https://esm.town/v/std/email?v=9";
2
3// Fetches a random joke.
4async function fetchRandomJoke() {
5 const response = await fetch(
6 "https://official-joke-api.appspot.com/random_joke",
7 );
9}
10
11const randomJoke = await fetchRandomJoke();
12const setup = randomJoke.setup;
13const punchline = randomJoke.punchline;

hungryWhiteLeoponmain.tsx16 matches

@gr8gatsby•Updated 8 months ago
1/**
2 * This application helps users write detailed reviews of coffee shops. It fetches coffee shop data
3 * from the OpenStreetMap Nominatim API, allows users to add custom details, and stores the augmented
4 * information in a SQLite database. The app provides a user interface to view, add, and edit coffee shop reviews.
25
26 useEffect(() => {
27 fetchReviews();
28 }, []);
29
30 const fetchCoffeeShops = async () => {
31 try {
32 const response = await fetch(`/api/coffee-shops?search=${encodeURIComponent(searchTerm)}`);
33 if (!response.ok) throw new Error("Failed to fetch coffee shops");
34 const data = await response.json();
35 setCoffeeShops(data);
36 } catch (error) {
37 console.error("Error fetching coffee shops:", error);
38 }
39 };
40
41 const fetchReviews = async () => {
42 try {
43 const response = await fetch("/api/reviews");
44 if (!response.ok) throw new Error("Failed to fetch reviews");
45 const data = await response.json();
46 setReviews(data);
47 } catch (error) {
48 console.error("Error fetching reviews:", error);
49 }
50 };
60
61 try {
62 const response = await fetch("/api/reviews", {
63 method: "POST",
64 headers: { "Content-Type": "application/json" },
75 additionalNotes: "",
76 });
77 fetchReviews();
78 } catch (error) {
79 console.error("Error submitting review:", error);
91 placeholder="Search for coffee shops"
92 />
93 <button onClick={fetchCoffeeShops}>Search</button>
94 </div>
95 <div className="results-section">
194 if (url.pathname === "/api/coffee-shops") {
195 const searchTerm = url.searchParams.get("search") || "";
196 // Fetch coffee shops from OpenStreetMap Nominatim API
197 const nominatimUrl = `https://nominatim.openstreetmap.org/search?q=coffee+${
198 encodeURIComponent(searchTerm)
199 }&format=json&addressdetails=1`;
200 const nominatimResponse = await fetch(nominatimUrl, {
201 headers: {
202 "User-Agent": "CoffeeShopReviewer/1.0",
224 if (request.method === "GET") {
225 const reviews = await sqlite.execute(`SELECT * FROM ${KEY}_coffee_reviews_${SCHEMA_VERSION}`);
226 console.log("Fetched reviews:", reviews.rows);
227 return new Response(JSON.stringify(reviews.rows), {
228 headers: { "Content-Type": "application/json" },

addToLogmain.tsx5 matches

@ejfox•Updated 8 months ago
19
20 useEffect(() => {
21 fetchMessages();
22 }, []);
23
24 const fetchMessages = async () => {
25 const response = await fetch("/messages");
26 const data = await response.json();
27 setMessages(data);
32 if (!newMessage.trim()) return;
33
34 await fetch("/messages", {
35 method: "POST",
36 headers: { "Content-Type": "application/json" },
39
40 setNewMessage("");
41 fetchMessages();
42 };
43

isMyWebsiteDownmain.tsx2 matches

@rareadmin•Updated 8 months ago
14 start = performance.now();
15 try {
16 const res = await fetch(url);
17 end = performance.now();
18 status = res.status;
25 } catch (e) {
26 end = performance.now();
27 reason = `couldn't fetch: ${e}`;
28 ok = false;
29 console.log(`Website down (${url}): ${reason} (${end - start}ms)`);

sqliteExplorerAppmain.tsx4 matches

@lukedenton•Updated 8 months ago
1/** @jsxImportSource https://esm.sh/hono@latest/jsx **/
2
3import { modifyFetchHandler } from "https://esm.town/v/andreterron/codeOnValTown?v=50";
4import { iframeHandler } from "https://esm.town/v/nbbaier/iframeHandler";
5import { resetStyle } from "https://esm.town/v/nbbaier/resetStyle";
16import { verifyToken } from "https://esm.town/v/pomdtr/verifyToken";
17import { ResultSet, sqlite } from "https://esm.town/v/std/sqlite";
18import { reloadOnSaveFetchMiddleware } from "https://esm.town/v/stevekrouse/reloadOnSave";
19import { Hono } from "npm:hono";
20import type { FC } from "npm:hono/jsx";
175});
176
177export const handler = app.fetch;
178export default iframeHandler(modifyFetchHandler(handler, { verifyPassword: verifyToken }));

valTownUsermain.tsx1 match

@iamseeley•Updated 8 months ago
9 cachedUser = await api('/v1/me', { authenticated: true });
10 } catch (error) {
11 console.error('Error fetching user info:', error);
12 return null;
13 }

apimain.tsx2 matches

@iamseeley•Updated 8 months ago
16
17 while (true) {
18 const resp = await fetch(url);
19 if (!resp.ok) {
20 throw new Error(await resp.text());
33 return { data } as T;
34 }
35 const resp = await fetch(`${API_URL}${path}`, {
36 ...options,
37 headers: {

valTownDataLogsmain.tsx1 match

@iamseeley•Updated 8 months ago
87
88 } catch (error) {
89 console.error('Error fetching user data or inspecting database:', error);
90 }
91}

valTownUserREADME.md1 match

@iamseeley•Updated 8 months ago
6
7### getUserInfo()
8Fetches and caches the user's information.
9- Use case: Retrieving all user details at once.
10```ts

allvalsmain.tsx4 matches

@ejfox•Updated 8 months ago
32 debugMessages.push(`User ID retrieved: ${user.id}`);
33
34 debugMessages.push(`Fetching vals for user ID: ${user.id}`);
35 let vals = [];
36 try {
38 vals.push(val);
39 }
40 debugMessages.push(`Vals fetched successfully. Number of vals: ${vals.length}`);
41 } catch (error) {
42 debugMessages.push(`Error fetching vals: ${error instanceof Error ? error.message : String(error)}`);
43 throw new Error(`Failed to fetch vals for user ID: ${user.id}`);
44 }
45

proxyFetch2 file matches

@vidar•Updated 2 days ago

TAC_FetchBasic2 file matches

@A7_OMC•Updated 2 days ago