Created
January 5, 2016 01:27
-
-
Save futurist/51c96022d819beab797f to your computer and use it in GitHub Desktop.
node make-http-request
This file contains hidden or 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
var request = require('request'); | |
var http = require('http'); | |
request.get('http://1111hui.com:4000/organizations/5673c95ae3b3e6e54937ede1/relationships/liaisons').on('response', function(res, body) { | |
console.log(res.statusCode, body) | |
}) | |
var postData = JSON.stringify( | |
{"data":[ { "type": "people", "id": "567364ce9f62d7e72ae5f7f3" }] } | |
); | |
var options = { | |
hostname: '1111hui.com', | |
port: 4000, | |
path: '/organizations/5673c95ae3b3e6e54937ede1/relationships/liaisons', | |
method: 'DELETE', | |
headers: { | |
'Content-Type': 'application/vnd.api+json', | |
'Content-Length': postData.length | |
} | |
}; | |
var req = http.request(options, function(res) { | |
console.log('STATUS: ' + res.statusCode); | |
console.log('HEADERS: ' + JSON.stringify(res.headers)); | |
res.setEncoding('utf8'); | |
res.on('data', function (chunk) { | |
console.log('BODY: ' + chunk); | |
}); | |
res.on('end', function() { | |
console.log('No more data in response.') | |
}) | |
}); | |
req.on('error', function(e) { | |
console.log('problem with request: ' + e.message); | |
}); | |
// write data to request body | |
req.write(postData); | |
req.end(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment