In this method, I have fetched a single API Request URL
function fetchData() {
let url = 'http://127.0.0.1:8000/api/onlineUserData';
fetch(url)
.then(response => response.json())
.then(data => {
var users=data.users;
console.log(data.users);
});
}
and when I do console.log(data.users). Result or data will come like this.
[["Month", "Anam", "Panam", "duliyan"], ["Apr-16", 21, 26, 29], ["May-07", 0, 0, 5]]
But now I want to fetch multiple URLs or API request and retrieve each API Request data at the same time. From this link I found the uses of promise but I don't how to use retrieve individual API Request Data How to fetch multiple API Request or URL at the same time?
function fetchData() {
let urls = [
'http://127.0.0.1:8000/api/onlineUserData',
'http://127.0.0.1:8000/api/offlineUserData'
]
let requests = urls.map(url => fetch(url));
Promise.all(requests)
.then(responses => responses.forEach(
response => console.log(`${response.url}: ${response.status}`)
));
}
console.log? what did you see?response? I am not giving you the answer. I am just giving you advice. You should think about that. tryconsole.log(response)instead ofconsole.log(response.url);