9
10 useEffect(() => {
11 async function fetchWeather() {
12 try {
13 const response = await fetch(
14 `https://api.open-meteo.com/v1/forecast?latitude=${location.latitude}&longitude=${location.longitude}¤t_weather=true&hourly=temperature_2m,relativehumidity_2m,windspeed_10m`
15 );
17 setWeatherData(data);
18 } catch (err) {
19 setError("Could not fetch weather data");
20 }
21 }
22
23 fetchWeather();
24 }, [location]);
25
8
9 useEffect(() => {
10 fetchTodos();
11 }, []);
12
13 async function fetchTodos() {
14 const response = await fetch("/todos");
15 const data = await response.json();
16 setTodos(data);
21 if (!newTodo.trim()) return;
22
23 const response = await fetch("/todos", {
24 method: "POST",
25 headers: { "Content-Type": "application/json" },
28
29 if (response.ok) {
30 await fetchTodos();
31 setNewTodo("");
32 }
34
35 async function toggleTodo(id: number, completed: boolean) {
36 const response = await fetch(`/todos/${id}`, {
37 method: "PATCH",
38 headers: { "Content-Type": "application/json" },
41
42 if (response.ok) {
43 await fetchTodos();
44 }
45 }
46
47 async function deleteTodo(id: number) {
48 const response = await fetch(`/todos/${id}`, {
49 method: "DELETE"
50 });
51
52 if (response.ok) {
53 await fetchTodos();
54 }
55 }
1import { email } from "https://esm.town/v/std/email?v=9";
2
3// Fetches a random joke.
4async function fetchRandomJoke() {
5 const response = await fetch(
6 "https://official-joke-api.appspot.com/random_joke",
7 );
9}
10
11const randomJoke = await fetchRandomJoke();
12const setup = randomJoke.setup;
13const punchline = randomJoke.punchline;
1import { discordWebhook } from "https://esm.town/v/stevekrouse/discordWebhook";
2import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
3import process from "node:process";
4
6let output = "**Hyderabad Weather Report**\n\n";
7const accuweatherCityCode = "202190";
8// fetch JSON daily from accuweather
9const getForecast = async () => {
10 const forecastData = await fetchJSON(
11 `http://dataservice.accuweather.com/forecasts/v1/daily/1day/${accuweatherCityCode}?apikey=${process.env.accuWeather}&details=true&metric=true`,
12 );
29 const [error, setError] = useState(null);
30
31 // Fetch businesses from server
32 const fetchBusinesses = async () => {
33 setIsLoading(true);
34 setError(null);
35
36 try {
37 const response = await fetch(`/api/search?postcode=${postcode}§or=${sector}`);
38
39 if (!response.ok) {
53 // Manual search function
54 const handleManualSearch = () => {
55 fetchBusinesses();
56 };
57
260 try {
261 // Use a business directory API (Replace with actual API)
262 const apiResponse = await fetch(`https://api.example.com/businesses?postcode=${postcode}§or=${sector}`, {
263 headers: {
264 'Authorization': `Bearer ${API_KEY}`,
268
269 if (!apiResponse.ok) {
270 throw new Error('Failed to fetch businesses');
271 }
272
3Proxied web browser for debugging new DNS records
4
5It's difficult to verify new DNS records. If you check too early, the old records may get cached on your computer, browser, or local network. This tool uses a proxied fetch so you can always view your web page uncached.
6
7Uses @std/fetch on the backend to ensure the DNS records of the request are from new places every request.
8
9Version 4 of this val also showed DNS records, pulled on the server,
17 ];
18
19 // Endpoint to fetch questions
20 if (new URL(request.url).pathname === '/questions') {
21 return new Response(JSON.stringify(defaultQuestions), {
284
285 function completeQuiz() {
286 fetch('/submit', {
287 method: 'POST',
288 headers: { 'Content-Type': 'application/json' },
358
359 startButton.addEventListener('click', function() {
360 // Use absolute URL for fetching questions
361 fetch(window.location.origin + '/questions')
362 .then(function(response) {
363 console.log('Fetch response status:', response.status);
364 if (!response.ok) {
365 throw new Error('Network response was not ok');
375 })
376 .catch(function(error) {
377 logError('Error fetching questions', error);
378 });
379 });
4const app = new Hono();
5
6async function fetchMovies(page = 1, limit = 20) {
7 const cacheKey = `movies_page_${page}_limit_${limit}`;
8
12 return cachedResponse;
13 }
14 const apiResponse = await fetch(
15 `https://api.zoechip.to/data/browse/?lang=3&keyword=&year=&rating=&votes=&genre=&country=&cast=&directors=&type=&order_by=trending&page=${page}&limit=${limit}`,
16 {
33 return data;
34 } catch (error) {
35 console.error("Failed to fetch movies:", error);
36 return { movies: [], pager: { totalPages: 0, currentPage: 1 } };
37 }
51app.get("/", async (c) => {
52 const page = Number(c.req.query("page") || "1");
53 const { movies, pager } = await fetchMovies(page);
54
55 return c.html(`
209app.get("/movie/:id", async (c) => {
210 const movieId = c.req.param("id");
211 const { movies } = await fetchMovies();
212 const movie = movies.find(m => m._id === movieId);
213
276});
277
278export default app.fetch;
1import { email } from "https://esm.town/v/std/email?v=9";
2
3// Fetches a random joke.
4async function fetchRandomJoke() {
5 const response = await fetch(
6 "https://official-joke-api.appspot.com/random_joke",
7 );
9}
10
11const randomJoke = await fetchRandomJoke();
12const setup = randomJoke.setup;
13const punchline = randomJoke.punchline;
4const app = createApp();
5
6export default lastlogin(app.fetch, {
7 verifyEmail: (email) => email === "spinningidea@gmail.com",
8});