2017-09-10 26 views
1

我有一些只能通过API网关服务器调用的后端服务。后端服务在Spring rest服务中,并且API GateWay是一个节点服务器。这两个服务器在不同端口(后端:8080,节点:3000)上本地运行。如何在本地运行的Web服务之间进行通信

如何向我的节点服务器请求后端服务?

回答

0

如果他们都暴露REST API时可以使用HTTP inbuilt-模块的通信

require('http'); 
     var options = { 
     host: 'www.google.com', 
     port: 80, 
     path: '/index.html' 
    }; 

    http.get(options, function(res) { 
     console.log("Got response: " + res.statusCode); 

     res.on("data", function(chunk) { 
     console.log("BODY: " + chunk); 
     }); 
    }).on('error', function(e) { 
     console.log("Got error: " + e.message); 
    }); 

但我会建议使用库,例如​​superagentaxios

+0

我不能够在当地之间的通信API的,关于如何存档的想法? –

相关问题