-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAPICall.js
More file actions
38 lines (33 loc) · 1 KB
/
APICall.js
File metadata and controls
38 lines (33 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const getCartAndProducts = async () => {
try {
console.time("api");
const res = await Promise.allSettled([
fetch("http://localhost:3000/products"),
fetch("http://localhost:3000/cart"),
]);
const resJSON = await Promise.allSettled(
res.map((x) => {
if (x.status === "fulfilled") {
return x.value.json();
}
return { error: true, message: x.reason.json() };
})
);
console.log(resJSON);
// console.log(resJSON);
// const productsRes = await fetch('http://localhost:3000/products');
// const productsJson = await productsRes.json();
// if(!productsRes.ok) {
// throw new Error(productsJson)
// }
// console.log(productsJson);
// const cartRes = await fetch('http://localhost:3000/cart');
// const cartJson = await cartRes.json();
// if(!cartRes.ok) {
// throw new Error(cartJson)
// }
// console.log(cartJson)
console.timeEnd("api");
} catch (error) {}
};
getCartAndProducts();