我需要一些帮助来解决这个问题,我需要运行:
exports.someFunction = function () {
// i need call a route like this.
app.route('api/getdata');
};
我需要在快递功能中调用一些路线。我该怎么办?
答案 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库。