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/?q=fetch&page=651&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 7883 results for "fetch"(1525ms)

syntheticLootmain.tsx6 matches

@jamiedubs•Updated 1 year ago
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);

searchWikipediamain.tsx4 matches

@jamiedubs•Updated 1 year ago
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" },

quote_of_the_daymain.tsx2 matches

@robik•Updated 1 year ago
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 );

weatherInCitymain.tsx2 matches

@jamiedubs•Updated 1 year ago
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" },

starWarsmain.tsx2 matches

@danny•Updated 1 year ago
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);

nasaAPODmain.tsx2 matches

@danny•Updated 1 year ago
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

untitled_magentaQuailmain.tsx4 matches

@shiann3•Updated 1 year ago
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;

getMemain.tsx2 matches

@stevekrouse•Updated 1 year ago
1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
2
3export function getMe(): Promise<{ username: string; id: string; profileImageUrl; bio: string }> {
4 return fetchJSON("https://api.val.town/v1/me", {
5 headers: {
6 Authorization: `Bearer ${Deno.env.get("valtown")}`,

codeOnValTownREADME.md6 matches

@andreterron•Updated 1 year ago
11Here are 2 different ways to add the "Code on Val Town" ribbon:
12
13### 1. Wrap your fetch handler (recommended)
14
15```ts
16import { modifyFetchHandler } from "https://esm.town/v/andreterron/codeOnValTown?v=50";
17import { html } from "https://esm.town/v/stevekrouse/html?v=5";
18
19export default modifyFetchHandler(async (req: Request): Promise<Response> => {
20 return html(`<h2>Hello world!</h2>`);
21});
51These functions infer the val using the call stack or the request URL. If the inference isn't working, or if you want to ensure it links to a specific val, pass the `val` argument:
52
53- `modifyFetchHandler(handler, {val: { handle: "andre", name: "foo" }})`
54- `modifyHtmlString("<html>...", {val: { handle: "andre", name: "foo" }})`
55
58You can set the style parameter to a css string to customize the ribbon. Check out [github-fork-ribbon-css](https://github.com/simonwhitaker/github-fork-ribbon-css?tab=readme-ov-file#styling) to learn more about how to style the element.
59
60- `modifyFetchHandler(handler, {style: ".github-fork-ribbon:before { background-color: #333; }"})`
61- `modifyHtmlString("<html>...", {style: ".github-fork-ribbon:before { background-color: #333; }"})`
62
64
65```ts
66modifyFetchHandler(handler, {style: `@media (max-width: 768px) {
67 .github-fork-ribbon {
68 display: none !important;

refreshAnimalWidgetmain.tsx2 matches

@crsven•Updated 1 year ago
1import { animalWidgetJson } from "https://esm.town/v/crsven/animalWidgetJson";
2import { fetchABird } from "https://esm.town/v/crsven/fetchABird";
3import { getBirdPhotoUrl } from "https://esm.town/v/crsven/getBirdPhotoUrl";
4import { getNextColorCombo } from "https://esm.town/v/crsven/getNextColorCombo";
6
7export let refreshAnimalWidget = async () => {
8 const bird = await fetchABird();
9 const photoUrl = await getBirdPhotoUrl(
10 `${bird.gen} ${bird.sp}`,

fetchPaginatedData2 file matches

@nbbaier•Updated 1 week ago

FetchBasic1 file match

@fredmoon•Updated 1 week ago