Sunday 25 November 2018

Noob needs an example of aggregating results in a webapp's get function

Subject hopefully provides the gist of what I am having trouble understanding as a noob.On a get to my web app, I want to make three http requests to JSON services and send the JSON to an EJS page.The part I am having trouble with is the async/promise part of retrieving the external data:app.get('/', function (req, res) {x = make http request 1y = make http request 2z = make http request 3res.render('index', { x:x, y:y, z:z, error:null });});I think I should be writing a function to make an http request to an external service and return a promise. Then maybe use Promise.all to wait until they have all completed and failed.I really would appreciate an example/shell of exactly how to do this.

Submitted November 25, 2018 at 12:11PM by OrganicUse

No comments:

Post a Comment