daily pastebin goal
7%
SHARE
TWEET

Untitled

a guest Sep 26th, 2018 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var express = require('express');
  2. var bodyParser = require('body-parser');
  3. var rp = require("request-promise");
  4.  
  5. var app = express();
  6. app.use(bodyParser.json());
  7.  
  8. app.post('/building/', function (req, res) {
  9.     'use strict';
  10.  
  11.     var myObject = null;
  12.  
  13.     var options = {
  14.         uri: 'http://localhost:8080/site/',
  15.         body: JSON.stringify(req.body),
  16.         method: 'POST',
  17.         headers: {
  18.             'Content-Type': 'application/json'
  19.         },
  20.         json: true
  21.     }
  22.     // First External API Call
  23.     rp(options).then((response) => {
  24.         var promises = response.body.floor.map(material => rp({
  25.             uri: "http://localhost:8080/material/" + i,
  26.             json: true
  27.         }).then(mat => rp({
  28.             uri: "http://localhost:8080/value/" + mat.whatever,
  29.             json: true
  30.         })));
  31.         // actual server reply here:
  32.         Promise.all(promises).then(materials => res.sendJSON(materials));
  33.     }).catch(error => {
  34.         console.log('ERROR with user request.');
  35.         return res.sendStatus(500); // Return back that an error occurred
  36.     });
  37. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top