如何在本地运行的Web服务之间进行通信

问题描述 投票:1回答:1

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

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

node.js spring http localhost spring-rest
1个回答
0
投票

如果它们都公开了其余的API,则可以使用内置的http模块进行通信

    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之类的

© www.soinside.com 2019 - 2024. All rights reserved.