1

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Is there a way to do this in the same node.js script?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.