Skip to content

Instantly share code, notes, and snippets.

@dinedal
Created November 7, 2011 22:17
Show Gist options
  • Save dinedal/1346383 to your computer and use it in GitHub Desktop.
Save dinedal/1346383 to your computer and use it in GitHub Desktop.
Sample code to send request to Chronicle
http = require 'http'
util= require 'util'
options = {
host: 'api.staging.cloud.vitrue.com',
port: 80,
path: '/chronicle/1/',
method: 'GET',
disable_ssl_peer_verification: true,
timeout: 200
headers: {
'accept': 'application/json',
'content-type': 'application/json',
'expect': '',
'X-Vitrue-API-Key': '95d9edc1-19f3-4626-a348-ab860b4ec381'
}
}
req = http.request options, (res) ->
console.log('STATUS: ' + res.statusCode)
console.log('HEADERS: ' + JSON.stringify(res.headers))
res.setEncoding('utf8')
res.on 'data', (chunk) ->
console.log('BODY: ' + chunk)
req.on 'error', (err) ->
console.log err
# console.log util.inspect req
req.write JSON.stringify("data")
req.end()
_______________________________
put_data = {'tag':{tag:'X'}}
request {uri:"https://api.staging.cloud.vitrue.com/chronicle/1/apps/abacus/clients/test/tags/tag1", method:'post', json:put_data, headers:{'X-Vitrue-API-Key':'95d9edc1-19f3-4626-a348-ab860b4ec381'}}, (error, response, body) ->
console.log util.inspect response
console.log util.inspect body
console.log util.inspect error if error
request.get {uri:"https://api.staging.cloud.vitrue.com/chronicle/1/"}, (error, res, body) ->
console.log util.inspect error if error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment