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/$%7Burl%7D?q=fetch&page=662&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 9191 results for "fetch"(2360ms)

sqlitemain.tsx2 matches

@heaversm•Updated 8 months ago
35
36async function execute(statement: InStatement, args?: InArgs): Promise<ResultSet> {
37 const res = await fetch(`${API_URL}/v1/sqlite/execute`, {
38 method: "POST",
39 headers: {
50
51async function batch(statements: InStatement[], mode?: TransactionMode): Promise<ResultSet[]> {
52 const res = await fetch(`${API_URL}/v1/sqlite/batch`, {
53 method: "POST",
54 headers: {

googleCalendarWeekEndpointmain.tsx4 matches

@ejfox•Updated 8 months ago
1// This approach uses Google OAuth to authenticate the user and fetch their actual calendar events for the week.
2// It requires setting up OAuth credentials in the Google Cloud Console and configuring environment variables in Val Town.
3
46
47 // Exchange code for tokens
48 const tokenResponse = await fetch("https://oauth2.googleapis.com/token", {
49 method: "POST",
50 headers: {
63 const tokens = await tokenResponse.json();
64
65 // Fetch calendar events for this week
66 const now = new Date();
67 const oneWeekLater = new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000);
68
69 const calendarResponse = await fetch(
70 `https://www.googleapis.com/calendar/v3/calendars/primary/events?` +
71 `timeMin=${now.toISOString()}` +

ReactStreamREADME.md2 matches

@lisardo•Updated 8 months ago
73```
74
75### Fetch data on the server to set initial props
76
77
79// example middleware
80async function getInitialProps (req: Request, res: Response, next) {
81 // fetch data or do async work to pass as props to the component
82 req.data = {
83 hello: "props",

ReactStreammain.tsx4 matches

@lisardo•Updated 8 months ago
6
7export type RequestHandler = (request: Request) => Promise<Response>;
8export type DataFetcher<T> = (request: Request) => Promise<T>;
9
10// export type DataRequest<T> = Request & { data: T };
132 return api(req);
133};
134const deprecatedGetInitiaProps = (getProps: DataFetcher<any>): Middleware => async (req, res, next) => {
135 if (!getProps) return next();
136 const data = await getProps(req);
144 /** DEPRECATED: Optional API request handler for all non-GET methods */
145 api?: RequestHandler;
146 /** DEPRECATED: data fetcher to set initial props based on request */
147 getInitialProps?: DataFetcher<any>;
148}

umbrellaRemindermain.tsx2 matches

@aleem•Updated 8 months ago
1import { email } from "https://esm.town/v/std/email?v=9";
2import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
3import { nominatimSearch } from "https://esm.town/v/stevekrouse/nominatimSearch";
4import { weatherGovGrid } from "https://esm.town/v/stevekrouse/weatherGovGrid";
14 lon,
15 });
16 let { properties: { periods } } = await fetchJSON(
17 grid.forecastHourly,
18 );

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 }));

proxyFetch2 file matches

@vidar•Updated 1 day ago

TAC_FetchBasic2 file matches

@A7_OMC•Updated 1 day ago