Huiming Teo
Huiming Teo

Reputation: 393

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.

Upvotes: 12

Views: 8156

Answers (3)

Negm Sherif
Negm Sherif

Reputation: 114

HTTP

HTTP provides an HTTP request API on the client and server. To use these functions, add the HTTP package to your project with $ meteor add http.

Upvotes: 0

debergalis
debergalis

Reputation: 11870

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.

Upvotes: 20

Raynos
Raynos

Reputation: 169391

if (Meteor.is_server) {
    var http = __meteor_bootstrap__.require("http")
    // talk to external HTTP API like you would in node.js
}

Upvotes: 3

Related Questions