Mashape API help


#1

I am quite new to Meteor and I am building an app that will utilize an API provided through Mashape. I am aware of this:

 Meteor.methods({checkTwitter: function (userId) {
      check(userId, String);
      this.unblock();
      try {
        var result = HTTP.call("GET", "http://api.twitter.com/xyz",
                               {params: {user: userId}});
        return true;
      } catch (e) {
        // Got a network error, time-out or HTTP error in the 400 or 500 range.
        return false;
      }
    }});

But I don’t know how to replicate this while passing in (for example) the api key.

The jquery way is quite simple for me, but meteor provides functionality for this and I am cutting back on my jquery crutch and am confused here.

Any help would be killer

jquery example:

$.ajax({
    url: 'https://SOMEAPI.p.mashape.com/', // The URL to the API. You can get this in the API page of the API you intend to consume
    type: 'GET', // The HTTP Method, can be GET POST PUT DELETE etc
    data: {}, // Additional parameters here
    datatype: 'json',
    success: function(data) { console.dir((data.source)); },
    error: function(err) { alert(err); },
    beforeSend: function(xhr) {
    xhr.setRequestHeader("X-Mashape-Authorization", "YOUR-MASHAPE-KEY"); // Enter here your Mashape key
    }
});

#2

so do you basically want to pass additional parameters to that http call?
if it is the case, you just need to add it in your params.
like that:

params = {
user:userId,
q: search,
api_key: key
}


#3

You can pass parameters to the HTTP.get() in the command string itself, or as the params property of the options object as @stanp says. So:

var result = HTTP.call("GET", "http://api.twitter.com/xyz?user="+userId+"&apiKey=abc123");

or:

var result = HTTP.call("GET", "http://api.twitter.com/xyz", {
  query: {
    user: userId,
    apiKey: "abc123"
  }
});

Documentation: http://docs.meteor.com/#/full/http_call


#4

Thanks for the help!

It was the request headers & problem solved.