Reputation: 149
So I'm working on a service that calls a subreddit and requests the hottest articles in JSON. Now Reddit likes that anyone using the reddit API modifies their User-Agent Header to be descriptive (here's a link on the format).
So using Node.JS and the Request plugin, I wrote something like this
var subreddit = 'somesupercoolsubreddit';
var stories = '5';
var options ={
url : url.parse(REDDIT_URL+"/r/"+subreddit+"/hot.json"+"?"+"limit="+stories),
headers : {'User-Agent' : 'Super Cool Reddit Service for Local Widgets! by /u/mrkaiser'},
json: true
};
request(options,function(err,response,body){
serverResponse.send(body);
});
But how do I know this worked? Is there some way to know if request header actually got populated or if Reddit got the right User-Agent?
Upvotes: 1
Views: 201
Reputation: 28795
Create another node script that waits for connections and outputs the headers. Change your reddit script to temporarily call the new script and verify the headers.
Upvotes: 1