3536async function execute(statement: InStatement, args?: InArgs): Promise<ResultSet> {
37const res = await fetch(`${API_URL}/v1/sqlite/execute`, {
38method: "POST",
39headers: {
5051async function batch(statements: InStatement[], mode?: TransactionMode): Promise<ResultSet[]> {
52const res = await fetch(`${API_URL}/v1/sqlite/batch`, {
53method: "POST",
54headers: {
googleCalendarWeekEndpointmain.tsx4 matches
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.
34647// Exchange code for tokens
48const tokenResponse = await fetch("https://oauth2.googleapis.com/token", {
49method: "POST",
50headers: {
63const tokens = await tokenResponse.json();
6465// Fetch calendar events for this week
66const now = new Date();
67const oneWeekLater = new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000);
6869const calendarResponse = await fetch(
70`https://www.googleapis.com/calendar/v3/calendars/primary/events?` +
71`timeMin=${now.toISOString()}` +
ReactStreamREADME.md2 matches
73```
7475### Fetch data on the server to set initial props
767779// example middleware
80async function getInitialProps (req: Request, res: Response, next) {
81// fetch data or do async work to pass as props to the component
82req.data = {
83hello: "props",
ReactStreammain.tsx4 matches
67export type RequestHandler = (request: Request) => Promise<Response>;
8export type DataFetcher<T> = (request: Request) => Promise<T>;
910// export type DataRequest<T> = Request & { data: T };
132return api(req);
133};
134const deprecatedGetInitiaProps = (getProps: DataFetcher<any>): Middleware => async (req, res, next) => {
135if (!getProps) return next();
136const data = await getProps(req);
144/** DEPRECATED: Optional API request handler for all non-GET methods */
145api?: RequestHandler;
146/** DEPRECATED: data fetcher to set initial props based on request */
147getInitialProps?: DataFetcher<any>;
148}
umbrellaRemindermain.tsx2 matches
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";
14lon,
15});
16let { properties: { periods } } = await fetchJSON(
17grid.forecastHourly,
18);
untitled_azureWhippetmain.tsx4 matches
1import { email } from "https://esm.town/v/std/email?v=9";
23// Fetches a random joke.
4async function fetchRandomJoke() {
5const response = await fetch(
6"https://official-joke-api.appspot.com/random_joke",
7);
9}
1011const randomJoke = await fetchRandomJoke();
12const setup = randomJoke.setup;
13const punchline = randomJoke.punchline;
hungryWhiteLeoponmain.tsx16 matches
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.
2526useEffect(() => {
27fetchReviews();
28}, []);
2930const fetchCoffeeShops = async () => {
31try {
32const response = await fetch(`/api/coffee-shops?search=${encodeURIComponent(searchTerm)}`);
33if (!response.ok) throw new Error("Failed to fetch coffee shops");
34const data = await response.json();
35setCoffeeShops(data);
36} catch (error) {
37console.error("Error fetching coffee shops:", error);
38}
39};
4041const fetchReviews = async () => {
42try {
43const response = await fetch("/api/reviews");
44if (!response.ok) throw new Error("Failed to fetch reviews");
45const data = await response.json();
46setReviews(data);
47} catch (error) {
48console.error("Error fetching reviews:", error);
49}
50};
6061try {
62const response = await fetch("/api/reviews", {
63method: "POST",
64headers: { "Content-Type": "application/json" },
75additionalNotes: "",
76});
77fetchReviews();
78} catch (error) {
79console.error("Error submitting review:", error);
91placeholder="Search for coffee shops"
92/>
93<button onClick={fetchCoffeeShops}>Search</button>
94</div>
95<div className="results-section">
194if (url.pathname === "/api/coffee-shops") {
195const searchTerm = url.searchParams.get("search") || "";
196// Fetch coffee shops from OpenStreetMap Nominatim API
197const nominatimUrl = `https://nominatim.openstreetmap.org/search?q=coffee+${
198encodeURIComponent(searchTerm)
199}&format=json&addressdetails=1`;
200const nominatimResponse = await fetch(nominatimUrl, {
201headers: {
202"User-Agent": "CoffeeShopReviewer/1.0",
224if (request.method === "GET") {
225const reviews = await sqlite.execute(`SELECT * FROM ${KEY}_coffee_reviews_${SCHEMA_VERSION}`);
226console.log("Fetched reviews:", reviews.rows);
227return new Response(JSON.stringify(reviews.rows), {
228headers: { "Content-Type": "application/json" },
1920useEffect(() => {
21fetchMessages();
22}, []);
2324const fetchMessages = async () => {
25const response = await fetch("/messages");
26const data = await response.json();
27setMessages(data);
32if (!newMessage.trim()) return;
3334await fetch("/messages", {
35method: "POST",
36headers: { "Content-Type": "application/json" },
3940setNewMessage("");
41fetchMessages();
42};
43
isMyWebsiteDownmain.tsx2 matches
14start = performance.now();
15try {
16const res = await fetch(url);
17end = performance.now();
18status = res.status;
25} catch (e) {
26end = performance.now();
27reason = `couldn't fetch: ${e}`;
28ok = false;
29console.log(`Website down (${url}): ${reason} (${end - start}ms)`);
sqliteExplorerAppmain.tsx4 matches
1/** @jsxImportSource https://esm.sh/hono@latest/jsx **/
23import { 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});
176177export const handler = app.fetch;
178export default iframeHandler(modifyFetchHandler(handler, { verifyPassword: verifyToken }));