Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How easy to call external Web APIs in Meteor?

Does (or will) Meteor provide a library to handle external Web API calls? E.g. to build a Meteor app that integrates with Facebook Graph API or Google Spreadsheet API.

like image 548
Huiming Teo Avatar asked Apr 11 '12 04:04

Huiming Teo


2 Answers

Meteor now includes the http package. First, run meteor add http. Then you can make HTTP requests on the server in either sync or async style:

// server sync
res = Meteor.http.get(SOME_URL);
console.log(res.statusCode, res.data);

// server async
Meteor.http.get(SOME_URL, function (err, res) {
  console.log(res.statusCode, res.data);
});

Same thing works on the client, but you have to use the async form.

like image 158
debergalis Avatar answered Oct 16 '22 23:10

debergalis


if (Meteor.is_server) {
    var http = __meteor_bootstrap__.require("http")
    // talk to external HTTP API like you would in node.js
}
like image 39
Raynos Avatar answered Oct 16 '22 23:10

Raynos