Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var express = require('express');
- var bodyParser = require('body-parser');
- var rp = require("request-promise");
- var app = express();
- app.use(bodyParser.json());
- app.post('/building/', function (req, res) {
- 'use strict';
- var myObject = null;
- var options = {
- uri: 'http://localhost:8080/site/',
- body: JSON.stringify(req.body),
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- },
- json: true
- }
- // First External API Call
- rp(options).then((response) => {
- var promises = response.body.floor.map(material => rp({
- uri: "http://localhost:8080/material/" + i,
- json: true
- }).then(mat => rp({
- uri: "http://localhost:8080/value/" + mat.whatever,
- json: true
- })));
- // actual server reply here:
- Promise.all(promises).then(materials => res.sendJSON(materials));
- }).catch(error => {
- console.log('ERROR with user request.');
- return res.sendStatus(500); // Return back that an error occurred
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement