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: {
89useEffect(() => {
10fetchSavedDrawings();
11}, []);
1213const fetchSavedDrawings = async () => {
14const response = await fetch('/list-drawings');
15const drawings = await response.json();
16setSavedDrawings(drawings);
1819const handleSave = async () => {
20const response = await fetch('/save-drawing', {
21method: 'POST',
22headers: { 'Content-Type': 'application/json' },
24});
25if (response.ok) {
26fetchSavedDrawings();
27}
28};
calendlyThisWeekEventsmain.tsx6 matches
1/**
2* This API integrates with Calendly to fetch personal events for the current week.
3* It returns the events as raw JSON.
4*
18try {
19// First, get the user's URI
20const userResponse = await fetch('https://api.calendly.com/users/me', {
21headers: {
22'Content-Type': 'application/json',
2627if (!userResponse.ok) {
28throw new Error(`Failed to fetch user data: ${userResponse.status} ${userResponse.statusText}`);
29}
3037const endOfWeek = new Date(today.setDate(today.getDate() - today.getDay() + 6));
3839// Now fetch the events using the user's URI
40const eventsUrl = `https://api.calendly.com/scheduled_events?user=${userUri}&min_start_time=${startOfWeek.toISOString()}&max_start_time=${endOfWeek.toISOString()}`;
4142const eventsResponse = await fetch(eventsUrl, {
43headers: {
44'Content-Type': 'application/json',
4849if (!eventsResponse.ok) {
50throw new Error(`Failed to fetch Calendly events: ${eventsResponse.status} ${eventsResponse.statusText}`);
51}
52
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" },