Skip to content

Instantly share code, notes, and snippets.

@smathy
Created December 2, 2011 22:25
Show Gist options
  • Save smathy/1425125 to your computer and use it in GitHub Desktop.
Save smathy/1425125 to your computer and use it in GitHub Desktop.
https = require 'https'
module.exports.request = ( options, success_handler, error_handler) ->
req_data = if options.data? then JSON.stringify options.data else ""
options['headers']['Content-length'] = req_data.length
req = https.request options, (res) ->
data = ''
res.on 'data', (c) ->
data += c
res.on 'end', ->
if 200 <= res.statusCode < 300
if success_handler? and data?
success_handler JSON.parse data
else
if error_handler?
error_handler res
else
console.log "Error: #{res.statusCode}\n#{data}"
req.write(req_data)
req.end()
@smathy
Copy link
Author

smathy commented Dec 2, 2011

Yeah, cool.

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