How to I consume the Promise.all fetch api json data? It works fine to pull it if I don\'t use Promise.all. With .all it actually returns the values of the query in the cons
Using Promise.all
to fetch the json responses of each of the API's-
CODE:
Promise.all([
API_1_Promise,
API_2_Promise,
API_3_Promise])
.then(allResults => console.log(allResults))
.catch(err => console.log(err))
In which API_1_Promise,API_2_Promise,API_3_Promise
is defined as
API_1_Promise = fetch(`API_URL_1`, { *Add required headers* }).then(response => response.json())
API_2_Promise = fetch(`API_URL_2`, { *Add required headers* }).then(response => response.json())
API_3_Promise = fetch(`API_URL_3`, { *Add required headers* }).then(response => response.json())
RESPONSE: This will print the array of responses from all the API calls In console-->
[JSON_RESPONSE_API1, JSON_RESPONSE_API2, JSON_RESPONSE_API3]