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=1186&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 14435 results for "fetch"(7845ms)

sqlitemain.tsx2 matches

@gz315200•Updated 9 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: {

servermain.tsx5 matches

@stevekrouse•Updated 9 months ago
8
9 useEffect(() => {
10 fetchSavedDrawings();
11 }, []);
12
13 const fetchSavedDrawings = async () => {
14 const response = await fetch('/list-drawings');
15 const drawings = await response.json();
16 setSavedDrawings(drawings);
18
19 const handleSave = async () => {
20 const response = await fetch('/save-drawing', {
21 method: 'POST',
22 headers: { 'Content-Type': 'application/json' },
24 });
25 if (response.ok) {
26 fetchSavedDrawings();
27 }
28 };

calendlyThisWeekEventsmain.tsx6 matches

@ejfox•Updated 9 months ago
1/**
2 * This API integrates with Calendly to fetch personal events for the current week.
3 * It returns the events as raw JSON.
4 *
18 try {
19 // First, get the user's URI
20 const userResponse = await fetch('https://api.calendly.com/users/me', {
21 headers: {
22 'Content-Type': 'application/json',
26
27 if (!userResponse.ok) {
28 throw new Error(`Failed to fetch user data: ${userResponse.status} ${userResponse.statusText}`);
29 }
30
37 const endOfWeek = new Date(today.setDate(today.getDate() - today.getDay() + 6));
38
39 // Now fetch the events using the user's URI
40 const eventsUrl = `https://api.calendly.com/scheduled_events?user=${userUri}&min_start_time=${startOfWeek.toISOString()}&max_start_time=${endOfWeek.toISOString()}`;
41
42 const eventsResponse = await fetch(eventsUrl, {
43 headers: {
44 'Content-Type': 'application/json',
48
49 if (!eventsResponse.ok) {
50 throw new Error(`Failed to fetch Calendly events: ${eventsResponse.status} ${eventsResponse.statusText}`);
51 }
52

sqlitemain.tsx2 matches

@heaversm•Updated 9 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 9 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 9 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 9 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 9 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 9 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 9 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" },

testWeatherFetcher1 file match

@sjaskeprut•Updated 12 hours ago

weatherFetcher1 file match

@sjaskeprut•Updated 12 hours ago