Skip to content

Instantly share code, notes, and snippets.

@prettymuchbryce
Created February 8, 2014 04:45
Show Gist options
  • Save prettymuchbryce/8876837 to your computer and use it in GitHub Desktop.
Save prettymuchbryce/8876837 to your computer and use it in GitHub Desktop.
//Request user data from gravatar
app.get("/gravatar/:email", function (req, res) {
if (!req.params.email || typeof req.params.email !== "string") {
res.send(400);
return;
}
var path = "/" + md5(req.params.email.toLowerCase().trim()) + ".json";
var options = {
host: 'en.gravatar.com',
port: 80,
path: path.toString(),
method: 'GET'
};
console.log(options.host+path);
var callback = function(response) {
var str = '';
//another chunk of data has been recieved, so append it to `str`
response.on('data', function (chunk) {
str += chunk;
});
//the whole response has been recieved, so we just print it out here
response.on('end', function () {
console.log(str);
});
};
http.get(options, callback).end();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment