Created
April 11, 2018 17:20
-
-
Save Californ1a/780528657cb46a4c4a33b7e93707d9ea to your computer and use it in GitHub Desktop.
merge data from multiple fetch request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fetch = require("node-fetch"); | |
const urls = ["http://35.185.40.23/", "http://distance.rip:23469/"]; | |
Promise.all(urls.map(fetch)) | |
.then(responses => Promise.all(responses.map(res => res.json()))) | |
.then(multiData => multiData.reduce((merge, data) => ({ | |
...merge, | |
...data | |
}), {})) | |
.then(merged => { | |
console.log(JSON.stringify(merged, null, 2)); | |
//whatever you're doing with the data here | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment