Parsing Reddit API – JavaScript & NPM package ‘Request’

Since I recently got extremely interested in Node stuff I wanted to play around with consuming JSON APIs using some NPM packages. I found two that did the job:

Here’s my example using ‘request’. I parsed the API for the Kendama subreddit and rendered each post’s title and body.


//consumeAPI.js

var request = require(‘request’);

request(‘http://www.reddit.com/r/kendama/.json?limit=5’, displayData);

function displayData(err, resp, body) {
if (err) {
console.log(err);
}
var jsonString = JSON.parse(body);
var arrayOfPosts = jsonString.data.children;

for (var i = 0; i < arrayOfPosts.length; i++) { console.log('--' + arrayOfPosts[i].data.title); console.log(' ' + arrayOfPosts[i].data.selftext + '\n'); } } [/javascript] And the result [text] $ node consumeAPI.js --Thoughts on transparents? Thinking about getting a transparent ozora from roots and was curious if the thin paint would be more prone to chipping or getting messed up. --TK16? Are the yellow Tk16s from amazon good? Heres the link:http://www.amazon.com/TK16-Master-Single-Color-Yellow/dp/B00EQJONNG/ref=sr_1_3?s=toys-and-games&ie=UTF8&qid=1424387722&sr=1-3&keywords=tk16+kendama#customerReviews --Sweets website down? I was looking to buy a HG but it looks like the websites down. Anyone know when ítll be back up? --Has anyone ordered from HiKendama? How is the paint, does it chip much? Sticky? Slick? How about the antique line? They look pretty rad, I kinda want one, but I am new to Kendama, so I am scared to spend the 30 dollars. --These look sick, anyone else gonna cop? [/text] Further Reading ---

Leave a Reply