8}
9
10export default app.fetch;
11
1fetch contents of a specific wikipedia page using `?title=`param. will return nothing if page doesn't exactly match. example: https://jamiedubs-wikipediapage.web.val.run/?title=Berlin
2
3for a more search-oriented approach, try https://www.val.town/v/jamiedubs/searchWikipedia
1export const fetchWikipediaContent = async (req: Request) => {
2 const url = new URL(req.url);
3 const title = url.searchParams.get("title");
15 encodeURIComponent(title)
16 }`;
17 const response = await fetch(apiUrl);
18 if (!response.ok) {
19 throw new Error(`HTTP error! status: ${response.status}`);
33 });
34 } catch (error) {
35 return new Response(`Error fetching Wikipedia content: ${error.message}`, {
36 status: 500, // Internal Server Error
37 headers: { "Content-Type": "text/plain" },
1import { fetch } from "https://esm.town/v/std/fetch";
2import process from "node:process";
3import { DOMParser } from "https://deno.land/x/deno_dom/deno-dom-wasm.ts";
4
5// I <3 ether.actor, very convenient for fetching on-chain data
6// it's a little slow - Alchemy or another RPC/API provider would be faster
7const url = `https://ether.actor/0x869ad3dfb0f9acb9094ba85228008981be6dbdde/tokenURI`;
11// const svg = `<svg xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMinYMin meet" viewBox="0 0 350 350"><style>.base { fill: white; font-family: serif; font-size: 14px; }</style><rect width="100%" height="100%" fill="black" /><text x="10" y="20" class="base">Grave Wand</text><text x="10" y="40" class="base">Ornate Chestplate</text><text x="10" y="60" class="base">Dragon's Crown of Protection</text><text x="10" y="80" class="base">War Belt</text><text x="10" y="100" class="base">"Fate Sun" Divine Slippers of Power</text><text x="10" y="120" class="base">Silk Gloves</text><text x="10" y="140" class="base">Necklace</text><text x="10" y="160" class="base">Bronze Ring</text></svg>`;
12
13async function fetchAndParseSvgFromJson(account: string) {
14 try {
15 const response = await fetch(`${url}/${account}`);
16 const dataUri = await response.text();
17
31 return decodedSvg; // or manipulate as needed
32 } catch (error) {
33 console.error("Error fetching or decoding SVG from JSON:", error);
34 }
35}
68 }
69
70 const svg = await fetchAndParseSvgFromJson(account);
71 const elements = parseElementsFromSvg(svg);
72 // const elements = parseElementsFromSvgUsingRegex(svg);
1// Stripping HTML from the final output before sending the response
2import { fetch } from "https://esm.town/v/std/fetch";
3
4export const searchClosestWiki = async (req: Request) => {
16 encodeURIComponent(searchQuery)
17 }&srwhat=text&format=json&utf8=1&origin=*`;
18 const searchResponse = await fetch(searchUrl);
19 const searchData = await searchResponse.json();
20
30 encodeURIComponent(pageTitle)
31 }&format=json&utf8=1&origin=*`;
32 const contentResponse = await fetch(contentUrl);
33 const contentData = await contentResponse.json();
34 const pageId = Object.keys(contentData.query.pages)[0];
43 });
44 } catch (err) {
45 return new Response(`Error fetching Wikipedia data: ${err.message}`, {
46 status: 500, // Internal Server Error
47 headers: { "Content-Type": "text/plain" },
1import { email } from "https://esm.town/v/std/email?v=9";
2import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
3
4export async function quote_of_the_day() {
5 const [qod] = await fetchJSON(
6 "https://zenquotes.io/api/today",
7 );
13
14 try {
15 const weatherResponse = await fetch(weatherApiUrl);
16 if (!weatherResponse.ok) {
17 throw new Error(`Weather API request failed with status: ${weatherResponse.status}`);
37 });
38 } catch (err) {
39 return new Response("Error fetching weather data: " + err.message, {
40 status: 500, // Internal Server Error
41 headers: { "Content-Type": "text/plain" },
1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
2
3// Explore the Star Wars universe, from StarWarsAPI
4export let starWars = fetchJSON(
5 "https://swapi.dev/api/people/1/",
6);
1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
2
3// Returns NASA's Astronomy Picture of the Day (APOD)
4export const nasaAPOD = fetchJSON("cutt.ly/T7ksirK");
5// Forked from @iBrokeit.nasaAPOD
6import { email } from "";
7
8// Fetches a random joke.
9async function fetchRandomJoke() {
10 const response = await fetch(
11 "https://official-joke-api.appspot.com/random_joke",
12 );
13 return response.json();
14}
15const randomJoke = await fetchRandomJoke();
16const setup = randomJoke.setup;
17const punchline = randomJoke.punchline;