Created
July 26, 2011 03:25
-
-
Save bdickason/1105888 to your computer and use it in GitHub Desktop.
Simple HTTP Request in NodeJS
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
getRequest: (callback) -> | |
options = { | |
host: config.host or 'yourserver' | |
port: config.port or 80 | |
path: config.path or '/api/' | |
method: config.method or 'GET' | |
tmp = [] # Russ at the NYC NodeJS Meetup said array push is faster | |
http.request _options, (res) -> | |
res.setEncoding 'utf8' | |
res.on 'data', (chunk) -> | |
tmp.push chunk # Throw the chunk into the array | |
res.on 'end', (e) -> | |
body = tmp.join('') | |
callback body # Just spit back the body, no headers! | |
.end() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bad, coffeescript sucks