Sending server API data to client

Hello, I am still pretty new to Meteor. Recently I got access to an API that I have been wanting to use for some time. I successfully connected using the HTTP package. But am now having issues transferring that data to the client. I basically want to perform a call on the server, then send that to the client and display it on the web page. If i run what I have right now, I get the data expected posted back into my terminal. I have tried using the Meteor.method, but to no avail. Any help is appreciated. Here is what I have so far.

if (Meteor.isServer) {


  var devId = "XXX";
  var authKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  var utcTimestamp = new moment().utc().format("YYYYMMDDHHmmss");
  var signature = CryptoJS.MD5(devId + "createsession" + authKey + utcTimestamp).toString();

HTTP.call( 'GET', 'http://api.smitegame.com/smiteapi.svc/createsessionjson/' + devId + '/' + signature + '/' + utcTimestamp, {

}, function( error, response ) {
if ( error ) {
  console.log( error );
 } else {
   console.log( response );

   var sessionId = response.data.session_id;
 }
  console.log("this is my sessionId " + sessionId);


  var signature = CryptoJS.MD5(devId + "getplayer" + authKey + utcTimestamp).toString();
HTTP.call( 'GET', 'http://api.smitegame.com/smiteapi.svc/getplayerjson/' + devId + '/' + signature + '/' + sessionId + '/' + utcTimestamp + '/' + 'Truextacy', {

}, function( error, response ) {
if ( error ) {
  console.log( error );
 } else {
   console.log( response );
 }
});
}); //ends session

} //ends isServer

You can accomplish this with meteor methods.

Just do

// server/server.js
Meteor.methods({
  returnHTTP(args) {
    return HTTP.call(...)
  }
})

react

// client/views/view.jsx
Component = new React.createClass({
  handleClick() {
    Meteor.call("returnHTTP", (err,res)=>{
      this.setState({dataToShow: res});
    }
  },
  render() {
    return (
      <div>
        <p>this is the data: {this.state.dataToShow}</p>
        <button onClick={this.handleClick}> Click to get data</button>
      </div>
    )
  }
})

Or in Blaze

// client/views/myTemplate.js
Session.setDefault("dataToShow", {});
Template.myTemplate.events({
  'click button':function(){
    Meteor.call("returnHTTP", function(err,res){
      Session.set("dataToShow", res);
    }) 
  }
});
Template.myTemplate.helpers({
  dataToShow:function(){
    return Session.get("dataToShow");
  }
})

//client/views/myTemplate.html
<template name="myTemplate">
  <p>This is the data: {{dataToShow}}</p>
  <button>Click to get data</button>
</template>
2 Likes