How to make an API call using meteor

How to make an API call using meteor

Asked on November 30, 2018 in Meteor.
Add Comment


  • 3 Answer(s)

    To defining and your checkTwitter Meteor.method inside a client-scoped block. Because you cannot call cross domain from the client unless using jsonp, you have to put this block in a Meteor.isServer block.

    As an a side, per the documentation, the client side Meteor.method of your checkTwitter function is nearely a stub of a server-side method. You need to check out the documentss for a full explanation of how server-side and client-side Meteor.methods work together.

    For Example code:

    if (Meteor.isServer) {
      Meteor.methods({
        checkTwitter: function () {
          this.unblock();
          return Meteor.http.call("GET", "http://search.twitter.com/search.json?q=perkytweets");
        }
      });
    }
     
    //invoke the server method
    if (Meteor.isClient) {
      Meteor.call("checkTwitter", function(error, results) {
        console.log(results.content); //results.data should be a JSON object
      });
    }
    
    Answered on November 30, 2018.
    Add Comment

    You must seem rudimentary – but the HTTP package does not come by default in your Meteor project and requires that you install it a la carte.

    On the command line either:

    1. Just Meteor:
      meteor add http
    2. Meteorite:
      mrt add http

    You see the below link and get the meteor documents:

    Meteor HTTP Docs

    Answered on November 30, 2018.
    Add Comment

    The Meteor.http.get on the client is asynchronous, so you need to provide a callback function :

    Meteor.http.call("GET",url,function(error,result){
      console.log(result.statusCode);
    });
    
    Answered on November 30, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.