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/?q=fetch&page=470&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 8149 results for "fetch"(1180ms)

gameplay_agentmain.tsx5 matches

@arthrod•Updated 5 months ago
7 * If you define your agent with {@link Connect4Agent} or {@link PokerAgent},
8 * then you can use {@link agentHandler} to create an http service that
9 * serves it. The service it creates is a standard fetch handler that can be
10 * used with a variety of different http server libraries.
11 *
48 * ]});
49 *
50 * Bun.serve({fetch: handler});
51 * ```
52 *
114
115/**
116 * Create standard fetch handler for an agent.
117 *
118 * Takes a list of agents and returns a handler that can be used to create an
119 * agent http endpoint.
120 * The handler implements the standard fetch interface and can be used with
121 * a variety of different http server libraries.
122 *
132 *
133 * @returns {(req: Request) => Promise<Response>} An async handler that can be
134 * used with an http server that supports the fetch interface.
135 */
136export function agentHandler<

whoIsHiringmain.tsx12 matches

@dxaginfo•Updated 5 months ago
61 }, [state.loading, state.hasMore]);
62
63 const fetchStories = async () => {
64 try {
65 const response = await fetch("/api/stories");
66 if (!response.ok) throw new Error("Failed to fetch dates");
67 const data = await response.json();
68 setStories(data);
70 }
71 catch (err) {
72 console.error("Error fetching stories:", err);
73 }
74 };
75
76 const fetchComments = async (query: string, story: string, page: number) => {
77 try {
78 dispatch({ type: "loading", value: true });
79 const response = await fetch(`/api/comments?query=${encodeURIComponent(query)}&story=${story}&page=${page}`);
80 if (!response.ok) throw new Error("Failed to fetch comments");
81 const data = await response.json();
82 setComments(prevComments => page === 1 ? data.hits : [...prevComments, ...data.hits]);
84 dispatch({ type: "loading", value: false });
85 } catch (err) {
86 console.error("Error fetching comments:", err);
87 dispatch({ type: "loading", value: false });
88 }
99 dispatch({ type: "hasMore", value: true });
100 dispatch({ type: "query", value: newQuery });
101 fetchComments(fullQuery, state.story, 1);
102 };
103
104 useEffect(() => {
105 fetchStories();
106
107 const handleScroll = () => {
122 : "";
123 const fullQuery = `${filtersQuery} ${state.query}`;
124 fetchComments(fullQuery, state.story, state.page);
125 }
126 }
391 tags: `comment, story_${story}`,
392 page: 0,
393 hitsPerPage: 100, // Fetch a moderate number of comments
394 });
395

lazyCookmain.tsx3 matches

@dxaginfo•Updated 5 months ago
20 setError("");
21 try {
22 const response = await fetch("/recipes", {
23 method: "POST",
24 headers: { "Content-Type": "application/json" },
32 }
33 } catch (err) {
34 setError("An error occurred while fetching recipes. Please try again.");
35 } finally {
36 setLoading(false);
339
340async function generateImage(recipeName: string): Promise<string> {
341 const response = await fetch(`https://maxm-imggenurl.web.val.run/${encodeURIComponent(recipeName)}`);
342 if (!response.ok) {
343 throw new Error(`Failed to generate image for ${recipeName}`);

savvyTealCardinalmain.tsx5 matches

@dxaginfo•Updated 5 months ago
51 setTrainingPlan("");
52 setYoutubeLinks([]);
53 const response = await fetch("/generate-training", {
54 method: "POST",
55 headers: { "Content-Type": "application/json", "Regenerate-Key": regenerateKey.toString() },
76 setSharing(true);
77 try {
78 const response = await fetch("/share-training", {
79 method: "POST",
80 headers: { "Content-Type": "application/json" },
801 const videoPlaceholders = trainingPlan.match(/\[VIDEO: .+?\]/g) || [];
802
803 // Fetch and embed YouTube videos
804 const youtubeLinks = [];
805 for (const placeholder of videoPlaceholders) {
897 encodeURIComponent(sport + " " + query)
898 }&key=${apiKey}&type=video&maxResults=1`;
899 const response = await fetch(searchUrl);
900 const data = await response.json();
901 if (data.error) {
907 }
908 } catch (error) {
909 console.error("Error fetching from YouTube API:", error);
910 }
911 }

getWeathermain.tsx3 matches

@tokyotribe•Updated 5 months ago
1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
2
3export async function getWeather(location: string): Promise<WeatherResponse> {
4 return fetchJSON(`https://wttr.in/${location}?format=j1`);
5}
6
315 <html>
316 <body>
317 <h1>Error Fetching Weather</h1>
318 <p>${error.message}</p>
319 </body>

getSiteMetadatamain.tsx2 matches

@nbbaier•Updated 5 months ago
9 return metadata;
10 } catch (err) {
11 console.error("Error fetching metadata:", err);
12 return null;
13 }
75);
76
77export default app.fetch;

versatileBrownClownfishmain.tsx5 matches

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

tiny_jest_examplemain.tsx1 match

@willthereader•Updated 5 months ago
11 const runTests = async () => {
12 try {
13 const response = await fetch("/run-tests", {
14 method: "POST",
15 headers: { "Content-Type": "application/json" },

fizzBuzzTestmain.tsx2 matches

@willthereader•Updated 5 months ago
113 const runTests = async () => {
114 try {
115 const response = await fetch("/run-tests", {
116 method: "POST",
117 headers: { "Content-Type": "application/json" },
234 } catch (error) {
235 console.error("Error in runTests:", error);
236 if (error instanceof TypeError && error.message.includes("Failed to fetch dynamically imported module")) {
237 return {
238 success: false,

cors_examplemain.tsx1 match

@stevekrouse•Updated 5 months ago
9 async function request(url, options) {
10 try {
11 const response = await fetch(url, options);
12 const status = response.status;
13 const data = await response.text();

fetchPaginatedData2 file matches

@nbbaier•Updated 1 week ago

FetchBasic1 file match

@fredmoon•Updated 1 week ago