Skip to content

Instantly share code, notes, and snippets.

@bdickason
Created July 26, 2011 03:25
Show Gist options
  • Select an option

  • Save bdickason/1105888 to your computer and use it in GitHub Desktop.

Select an option

Save bdickason/1105888 to your computer and use it in GitHub Desktop.
Simple HTTP Request in NodeJS
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()
@aj07mm
Copy link
Copy Markdown

aj07mm commented Jan 15, 2016

bad, coffeescript sucks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment