title: How to call other REST APIs from your node micro-service and send the result as a response?
body: <p>I am currently trying to implement a BFF (backend for front end architecture).</p>
  
  <p>Using <code>request-promise</code> library I can successfully hit the other microservice but not able to return the result as a response from BFF microservice.</p>
  
  <p>Each time it is returning this result <code>Promise { pending }</code> pending state, could somebody please help me out on this?</p>
  
  <p>My main issue is to know how to receive data into BFF microservice from the other microservice that we are hitting and returning the result from microservice which is hitting other one.</p>
  
  <p>Or if somebody could help me to let know how to access the result from inside <code>.then</code> of any promise?</p>
  
  <p>The flow is like this:</p>
  
  <pre><code>client(ios/android)===(sends request)==&gt;BFF Microservice==&gt;BP microservice
  </code></pre>
  
  <p>(BFF Microservice handles the request and returns the response on the basis of result received from other microservice)</p>
  
  <p>Microservice code which is calling another microservice:</p>
  
  <pre><code>import yagmodel from '../../lib/models/yag-model'
  import {errorsList} from '../../lib/errors/errorsList'
  import request from 'request-promise'
  import config from 'config'
  
  //template below to call the REST APIs of other microservices.
  
  export async function getAllBP (req,res) {
      let yagresponse// this varaible is defined to get data from inside(rs.then )
  
      const username= req.swagger.params.username.value
      const authheader= req.swagger.params.Authorization.value
      console.log("Authorization:"+authheader)
  
      let rs= await yagmodel.bp(username,authheader)
      console.log(rs)
  
      rs.then((response)=&gt;{
          // console.log(response.body)
          yagresponse=response.body
          //console.log(rsp)
      }).catch((err)=&gt;{
          console.log(err)
          console.log('errorstatuscode:'+err.statusCode)
      })
  
      res.status(200).send(yagresponse) 
  }
  </code></pre>
  
  <p><code>yag-model.js</code> code:</p>
  
  <pre><code>import {errorsList} from '../../lib/errors/errorsList'
  import request from 'request-promise'
  
  module.exports.bp = async function getBP(username,authheader){
      const options={
          uri: `http://localhost:4000/Health/BP/`+username,
          json: true,
          resolveWithFullResponse: true,
          headers: {
              'Content-Type': 'application/json; charset=utf-8',
              'Accept': 'application/json; charset=utf-8',
              'Authorization':authheader
          },
          method: 'GET'
      }
  
      return request(options).then ((response)=&gt;{
          return response.body        
      }).catch((err)=&gt;{
          console.log(err)
          console.log('errorstatuscode:'+err.statusCode)
      })
  }
  </code></pre>