Skip to content Skip to sidebar Skip to footer

How To Make A Simple Http Request In Meteor From Client To Server

I'm using Meteor for first time and i'm trying to have a simple http call within a method so i can call this method from the client. The problem is that this async call it's keep r

Solution 1:

You should use the synchronous version of HTTP.post in this case. Give something like this a try:

Meteor.methods({
  getToken: function() {
    var appUrl = 'myAppUrl';
    vardata = {apiKey: 'mykey', apiSecret: 'mySecret'};
    try {
      var result = HTTP.post(appUrl, {data: data});
      return result;
    } catch (err) {
      return err;
    }
  } 
});

Instead of returning the err I'd recommend determining what kind of error was thrown and then just throw new Meteor.Error(...) so the client can see the error as its first callback argument.

Post a Comment for "How To Make A Simple Http Request In Meteor From Client To Server"