我正在尝试访问远程服务器API并需要进行ajax调用。最好是从服务器端完成,以免损害API密钥。我怎么用流星做到这一点?
答案 0 :(得分:3)
目前的方式似乎是通过http包。
首先将其添加到您的项目中:meteor add http
。然后你可以像这样使用它:
var result = HTTP.call("GET", "http://api.twitter.com/xyz",
{params: {user: userId}});
答案 1 :(得分:2)
如果是休息API,您可能希望使用Meteor.http.post
(文档here)。类似的东西:
Meteor.http.post(API_URL, {foo: 'bar', other: 'data'}, function(err, result) {
if (!err)
// do something with the result.
});
这也适用于客户方。