Meteor服务器端ajax

4

我想访问远程服务器API并需要进行ajax调用。最好是在服务器端完成,以免危及API密钥。使用meteor应该如何实现呢?

2个回答

3
目前使用的方法似乎是通过 http 包。
首先像这样将其添加到您的项目中:meteor add http。 然后您可以像这样使用它:
var result = HTTP.call("GET", "http://api.twitter.com/xyz",
  {params: {user: userId}});

2
如果是一个rest API,你可能想使用Meteor.http.post(文档在这里)。类似以下内容:
Meteor.http.post(API_URL, {foo: 'bar', other: 'data'}, function(err, result) {
  if (!err)
    // do something with the result.
});

这也适用于客户端。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接