Created
February 8, 2014 04:45
-
-
Save prettymuchbryce/8876837 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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