JSON and HandleBars

Try out some of the other methods and compare the outputs to the given output. See if you Here is a few Examples of calls using the Steam API


Using HandleBars and JSON


Enter the following in 'server.js'

app.get('/', function(httpRequest, httpResponse) {
var url='http://api.steampowered.com/ISteamUserStats/GetPlayerAchievements/v0001/?appid=22380&key='+key+'&steamid='+steamID;
request.get(url, function(error, sResponse, sBody) {
function playerstats(id, gName, pAchievement) {
this.steamID = id;
this.gameName = gName;
this.achievements = pAchievement.slice();
}
var finalObj = new playerstats(
JSON.parse( sBody ).playerstats.steamID,
JSON.parse( sBody ).playerstats.gameName,
JSON.parse( sBody ).playerstats.achievements
);
//console.log(finalObj.achievements);
httpResponse.render('home', {finalObj}); });
});
  1. First we create an object called Player Stats which will hold the data that is returned by the API.
    function playerstats(id, gName, pAchievement) {
    this.steamID = id;
    this.gameName = gName;
    this.achievements = pAchievement.slice();
    }

  2. Now parse the JSON data into a new instance of the Player Stats of the object.
    var finalObj = new playerstats(
    JSON.parse( sBody ).playerstats.steamID,
    JSON.parse( sBody ).playerstats.gameName,
    JSON.parse( sBody ).playerstats.achievements
    );

  3. Then send the object. In this case we are sending it to a file called home.handlebars
    httpResponse.render('home', {finalObj}); });


Home.handlebars


Make the handlebar code look like so and you should be able to see the formatted output of the JSON data.

handlebars
64x64

HOME

The Steam Api doesn’t allow for cross-origin so first we will have to create our own server using Node!

Setup Node Server

The Steam Api doesn’t allow for cross-origin so first we will have to create our own server using Node!

API Setup

Set up the Steam API!

GetPlayerAchievements

Use The API for the first time.

JSON and HandleBars

Learn how to Use JSON and Handlebars together.

Examples

A few Example Calls to get you familiar with the API.