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/image-url.jpg%20%22Optional%20title%22?q=fetch&page=701&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 9515 results for "fetch"(1849ms)

turnitdownmain.tsx1 match

@yawnxyz•Updated 8 months ago
83
84export default async function server(req: Request): Promise<Response> {
85 return app.fetch(req);
86}

iconExplorermain.tsx5 matches

@all•Updated 9 months ago
2 * This val creates an enhanced NPM package explorer using the npm registry API.
3 * It displays a grid of npm packages with basic information, categories, and navigation.
4 * The approach uses React for the frontend and fetch for API calls.
5 * It includes a details view for each package, a link to the npm page, and category navigation.
6 */
20
21 useEffect(() => {
22 fetchPackages();
23 }, [searchTerm, category, page]);
24
25 const fetchPackages = () => {
26 let url = `/search?q=${encodeURIComponent(searchTerm)}&size=${ITEMS_PER_PAGE}&from=${(page - 1) * ITEMS_PER_PAGE}`;
27 if (category !== "all") {
28 url += `&category=${encodeURIComponent(category)}`;
29 }
30 fetch(url)
31 .then(response => response.json())
32 .then(data => setPackages(data.objects));
114 }
115
116 const response = await fetch(apiUrl);
117 const data = await response.json();
118 return new Response(JSON.stringify(data), {

todaystatsmain.tsx45 matches

@ejfox•Updated 9 months ago
1/**
2 * This tool fetches real-time data from various free APIs to create a JSON object
3 * representing the current state of the world from different perspectives.
4 * Data is cached for 30 minutes using Val Town's SQLite database to reduce API calls and improve performance.
21}
22
23// Utility function for fetching JSON data
24async function fetchJSON(url: string) {
25 try {
26 const response = await fetch(url);
27 if (!response.ok) {
28 throw new Error(`HTTP error! status: ${response.status}`);
30 return await response.json();
31 } catch (error) {
32 console.error(`Error fetching ${url}:`, error);
33 return null;
34 }
40}
41
42// Utility function for fetching Wolfram Alpha data
43async function fetchWolframData(query: string) {
44 const appId = 'K8UTGR-8Y5G3A3VTP';
45 const url = `http://api.wolframalpha.com/v1/result?appid=${appId}&i=${encodeURIComponent(query)}`;
46 try {
47 const response = await fetch(url);
48 if (!response.ok) {
49 throw new Error(`HTTP error! status: ${response.status}`);
51 return await response.text();
52 } catch (error) {
53 console.error(`Error fetching Wolfram data for query "${query}":`, error);
54 return null;
55 }
56}
57
58// Utility function for fetching Alpha Vantage stock data
59async function fetchStockData(symbol: string) {
60 const apiKey = 'TD7I78XY3N2AGKWP';
61 const url = `https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=${symbol}&interval=5min&apikey=${apiKey}`;
62 try {
63 const data = await fetchJSON(url);
64 if (data && data['Time Series (5min)']) {
65 const latestTimestamp = Object.keys(data['Time Series (5min)'])[0];
70 }
71 } catch (error) {
72 console.error(`Error fetching stock data for symbol ${symbol}:`, error);
73 return null;
74 }
90 }
91
92 // If no valid cache, fetch new data
93 const issData = await fetchJSON('http://api.open-notify.org/iss-now.json');
94 const weatherData = await fetchJSON('https://api.open-meteo.com/v1/forecast?latitude=40.71&longitude=-74.01&current_weather=true&temperature_unit=celsius&daily=temperature_2m_max,temperature_2m_min,sunrise,sunset&timezone=America%2FNew_York');
95 const airQualityData = await fetchJSON('https://api.waqi.info/feed/geo:40.71;-74.01/?token=demo');
96 const cryptoData = await fetchJSON('https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,ethereum,dogecoin,ripple,cardano,polkadot,litecoin&vs_currencies=usd');
97 const peopleInSpaceData = await fetchJSON('http://api.open-notify.org/astros.json');
98 const timeData = await fetchJSON('https://worldtimeapi.org/api/timezone/America/New_York,Europe/London,Asia/Tokyo');
99 const exchangeRateData = await fetchJSON('https://api.exchangerate-api.com/v4/latest/USD');
100 const usaCovidData = await fetchJSON('https://disease.sh/v3/covid-19/countries/USA');
101 const solarData = await fetchJSON('https://services.swpc.noaa.gov/json/solar-cycle/observed-solar-cycle-indices.json');
102 const earthquakeData = await fetchJSON('https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson');
103
104 const worldPopulation = await fetchWolframData('current world population');
105 const carbonDioxide = await fetchWolframData('current atmospheric CO2');
106 const internetUsers = await fetchWolframData('number of internet users');
107 const globalTemperature = await fetchWolframData('current global average temperature');
108 const moonPhase = await fetchWolframData('current moon phase');
109 const usUnemploymentRate = await fetchWolframData('current US unemployment rate');
110 const globalInflationRate = await fetchWolframData('current global inflation rate');
111 const oilPrice = await fetchWolframData('current oil price');
112 const goldPrice = await fetchWolframData('current gold price');
113
114 const sp500 = await fetchStockData('SPY');
115 const dowJones = await fetchStockData('DIA');
116 const nasdaq = await fetchStockData('QQQ');
117 const appleStock = await fetchStockData('AAPL');
118 const nvidiaStock = await fetchStockData('NVDA');
119 const teslaStock = await fetchStockData('TSLA');
120 const amazonStock = await fetchStockData('AMZN');
121 const googleStock = await fetchStockData('GOOGL');
122
123 const worldState = {
267 </div>
268 <script>
269 async function fetchData() {
270 try {
271 const response = await fetch(window.location.href);
272 const data = await response.json();
273 document.getElementById('data').textContent = JSON.stringify(data, null, 2);
274 } catch (error) {
275 console.error('Error:', error);
276 document.getElementById('data').textContent = 'Error fetching data';
277 }
278 }
279 fetchData();
280 </script>
281</body>

daisyui_honomain.tsx1 match

@lnncoco•Updated 9 months ago
39});
40
41export default app.fetch;

nasamain.tsx20 matches

@ejfox•Updated 9 months ago
1/**
2 * This program creates an HTTP server that fetches various data from NASA APIs
3 * and returns a JSON response with a collection of interesting information about today.
4 * It uses multiple NASA APIs to gather diverse space-related data, including real-time imagery
10const NASA_API_KEY = 'vYg1cCNLVbcgNemMWuLEjoJsGOGbBXZjZjmwVwuV';
11
12async function fetchNASAData() {
13 const today = new Date().toISOString().split('T')[0];
14
15 // Fetch Astronomy Picture of the Day
16 const apodResponse = await fetch(`https://api.nasa.gov/planetary/apod?api_key=${NASA_API_KEY}`);
17 const apodData = await apodResponse.json();
18
19 // Fetch latest EPIC image metadata
20 const epicResponse = await fetch(`https://api.nasa.gov/EPIC/api/natural?api_key=${NASA_API_KEY}`);
21 const epicData = await epicResponse.json();
22 const latestEpicImage = epicData[0];
23
24 // Fetch Near Earth Objects for today
25 const neowsResponse = await fetch(`https://api.nasa.gov/neo/rest/v1/feed?start_date=${today}&end_date=${today}&api_key=${NASA_API_KEY}`);
26 const neowsData = await neowsResponse.json();
27
28 // Fetch Mars Weather data (note: this data is not always up-to-date)
29 const marsWeatherResponse = await fetch(`https://api.nasa.gov/insight_weather/?api_key=${NASA_API_KEY}&feedtype=json&ver=1.0`);
30 const marsWeatherData = await marsWeatherResponse.json();
31
32 // Fetch Earth Observatory Natural Event Tracker (EONET) data
33 const eonetResponse = await fetch(`https://eonet.gsfc.nasa.gov/api/v3/events`);
34 const eonetData = await eonetResponse.json();
35
36 // Fetch ISS Current Location
37 const issResponse = await fetch('http://api.open-notify.org/iss-now.json');
38 const issData = await issResponse.json();
39
40 // Fetch NASA Image and Video Library data
41 const nasaLibraryResponse = await fetch(`https://images-api.nasa.gov/search?q=space&media_type=image`);
42 const nasaLibraryData = await nasaLibraryResponse.json();
43
44 // Fetch TLE (Two-Line Element) data for satellites
45 const tleResponse = await fetch('https://www.celestrak.com/NORAD/elements/gp.php?GROUP=active&FORMAT=json');
46 const tleData = await tleResponse.json();
47
105export default async function server(request: Request): Promise<Response> {
106 try {
107 const nasaData = await fetchNASAData();
108 return new Response(JSON.stringify(nasaData, null, 2), {
109 headers: { 'Content-Type': 'application/json' },
110 });
111 } catch (error) {
112 return new Response(JSON.stringify({ error: 'Failed to fetch NASA data' }), {
113 status: 500,
114 headers: { 'Content-Type': 'application/json' },

hnmain.tsx1 match

@maxm•Updated 9 months ago
135
136 // Proceed with the proxy request
137 let resp = await fetch("https://news.ycombinator.com" + url.pathname + url.search, {
138 headers: req.headers,
139 method: req.method,

sqliteExplorerAppmain.tsx4 matches

@andrewn•Updated 9 months ago
1/** @jsxImportSource https://esm.sh/hono@latest/jsx **/
2
3import { 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});
176
177export const handler = app.fetch;
178export default iframeHandler(modifyFetchHandler(passwordAuth(handler, { verifyPassword: verifyToken })));

emailmain.tsx1 match

@shouser•Updated 9 months ago
68 headers?: Record<string, string>;
69}) => {
70 let result = await fetch(
71 `${API_URL}/v1/email`,
72 {

reluctantCoffeeGayalmain.tsx7 matches

@kaz•Updated 9 months ago
44
45 useEffect(() => {
46 fetchAnswersAndRankings();
47 }, [user]);
48
49 const fetchAnswersAndRankings = async () => {
50 if (user) {
51 const response = await fetch("/api/answers");
52 const data = await response.json();
53 setAnswers(data.answers);
59 const saveAnswer = useCallback(async (newAnswer: Answer, losingAnswer: string) => {
60 if (user) {
61 await fetch("/api/answer", {
62 method: "POST",
63 headers: { "Content-Type": "application/json" },
64 body: JSON.stringify({ ...newAnswer, losingAnswer }),
65 });
66 fetchAnswersAndRankings();
67 }
68 }, [user]);
70 const clearAnswers = useCallback(async () => {
71 if (user) {
72 await fetch("/api/clear-answers", { method: "POST" });
73 setAnswers([]);
74 setRankings([]);
242 const handleLogin = useCallback(async (e: React.FormEvent) => {
243 e.preventDefault();
244 const response = await fetch("/api/login", {
245 method: "POST",
246 headers: { "Content-Type": "application/json" },

fancyPlumSquirrelmain.tsx7 matches

@cofsana•Updated 9 months ago
1/**
2 * This val creates an elegant and professional web app for managing panel members for the State Street discussion.
3 * It uses React for the UI, SQLite for storing panel member information, and the Fetch API to communicate with the server.
4 * The design is clean and sophisticated, with a muted color palette and subtle animations.
5 */
16
17 useEffect(() => {
18 fetchPanelMembers();
19 }, []);
20
21 const fetchPanelMembers = async () => {
22 setIsLoading(true);
23 try {
24 const response = await fetch("/panel-members");
25 if (!response.ok) {
26 throw new Error("Failed to fetch panel members");
27 }
28 const data = await response.json();
39 setIsLoading(true);
40 try {
41 const response = await fetch("/add-member", {
42 method: "POST",
43 headers: { "Content-Type": "application/json" },
48 }
49 setNewMember({ name: "", expertise: "" });
50 fetchPanelMembers();
51 } catch (err) {
52 setError("Failed to add panel member. Please try again.");

agentplex-deal-flow-email-fetch1 file match

@anandvc•Updated 6 hours ago

proxyFetch2 file matches

@vidar•Updated 2 days ago