-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path25-Day.js
26 lines (23 loc) · 974 Bytes
/
25-Day.js
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
// This function makes multiple API calls in parallel using async/await
async function fetchMultipleData(urls) {
try {
// Use Promise.all to make multiple API calls and wait for all of them to resolve
const responses = await Promise.all(urls.map(url => fetch(url)));
// Extract the response data from each API call and return as an array
const data = await Promise.all(responses.map(response => response.json()));
return data;
} catch (error) {
// Return the error message if any of the API calls fail
return error.message;
}
}
// Example usage
const urls = [
"https://jsonplaceholder.typicode.com/posts/1",
"https://jsonplaceholder.typicode.com/comments/1",
"https://jsonplaceholder.typicode.com/albums/1"
];
// Call the function with the URLs and log the array of responses
fetchMultipleData(urls)
.then(responses => console.log(responses))
.catch(error => console.log(error));