如何从快速控制器调用和HTTP路由?

时间:2016-09-15 13:37:12

标签: api express meanjs controllers

我需要一些帮助来解决这个问题,我需要运行:

 exports.someFunction = function () {
   // i need call a route like this.
   app.route('api/getdata');
};

我需要在快递功能中调用一些路线。我该怎么办?

1 个答案:

答案 0 :(得分:0)

我假设/api/getdata返回您需要使用的某种数据(格式类似于JSON)。在这种情况下,它非常简单,只需使用Node优秀的unirest库。对于这种情况,我发现Node http有点先进。假设这是一个GET请求,它看起来像是:

unirest.post('http://example.com/api/getdata').end(function (response) {
  console.log(response.body);
});

当然,如果您愿意,可以使用Node http.get或您喜欢的任何其他HTTP库。