0% found this document useful (0 votes)
7 views1 page

Apihub Js

The document contains a JavaScript file that defines a function to fetch JSON data from various APIs with a default timeout. It utilizes the Fetch API and handles multiple requests concurrently using Promise.allSettled. The results include time, quotes, cryptocurrency prices, IP information, random facts, activities, geographical data, and weather based on geographical coordinates.

Uploaded by

cerealwater2018
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Apihub Js

The document contains a JavaScript file that defines a function to fetch JSON data from various APIs with a default timeout. It utilizes the Fetch API and handles multiple requests concurrently using Promise.allSettled. The results include time, quotes, cryptocurrency prices, IP information, random facts, activities, geographical data, and weather based on geographical coordinates.

Uploaded by

cerealwater2018
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

2/12/26, 12:13 AM apiHub.

js

src/core/[Link]

1 const DEFAULT_TIMEOUT = 6500;


2
3 const fetchJson = async (url, timeout = DEFAULT_TIMEOUT) => {
4 const controller = new AbortController();
5 const timer = setTimeout(() => [Link](), timeout);
6 try {
7 const res = await fetch(url, {
8 signal: [Link],
9 cache: "no-store",
10 headers: { Accept: "application/json" },
11 });
12 if (![Link]) throw new Error(`Bad response ${[Link]}`);
13 return await [Link]();
14 } finally {
15 clearTimeout(timer);
16 }
17 };
18
19 export const fetchApiBundle = async () => {
20 const [timeRes, quoteRes, cryptoRes, ipRes, factRes, activityRes, geoRes] = await [Link]([
21 fetchJson("[Link]
22 fetchJson("[Link]
23 fetchJson("[Link]
24 fetchJson("[Link]
25 fetchJson("[Link]
26 fetchJson("[Link]
27 fetchJson("[Link]
28 ]);
29
30 const geo = [Link] === "fulfilled" ? [Link] : null;
31 let weather = null;
32 if (geo?.latitude && geo?.longitude) {
33 const weatherRes = await [Link]([
34 fetchJson(
35 `[Link]
latitude=${[Link]}&longitude=${[Link]}&current=temperature_2m,apparent_temperature­
,precipitation,wind_speed_10m&timezone=
36 ),
37 ]);
38 weather = weatherRes[0].status === "fulfilled" ? weatherRes[0].value : null;
39 }
40
41 return {
42 time: [Link] === "fulfilled" ? [Link] : null,
43 quote: [Link] === "fulfilled" ? [Link] : null,
44 crypto: [Link] === "fulfilled" ? [Link] : null,
45 ip: [Link] === "fulfilled" ? [Link] : null,
46 fact: [Link] === "fulfilled" ? [Link] : null,
47 activity: [Link] === "fulfilled" ? [Link] : null,
48 geo,
49 weather,
50 };
51 };
52

localhost:54749/d518eb2f-87bc-4fa7-a963-390d2140858a/ 1/1

You might also like