Created
December 29, 2012 22:31
-
-
Save dandrews/4409729 to your computer and use it in GitHub Desktop.
An example making a secure GET request to the AngelList API, using Node.js. The results are written to a file. Invoke from the command line with: node angellist_get_request.js
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 https = require('https'); | |
var fs = require('fs'); | |
var key_token = 'your_access_token'; // optional | |
var startup_id = '6702'; // AngelList | |
// options for GET | |
var optionsget = { | |
host : 'api.angel.co', | |
port : 443, | |
// path : '/1/startups/' + startup_id, // no access_token | |
path : '/1/startups/' + startup_id + '?access_token=' + key_token, | |
method : 'GET' // do GET | |
}; | |
console.info('Options prepared:'); | |
console.info(optionsget); | |
console.info('Do the GET call'); | |
// do the GET request | |
var startupGet = https.request(optionsget, function(response) { | |
var startupData = ''; | |
console.log("statusCode: ", response.statusCode); | |
// uncomment it for header details | |
// console.log("headers: ", response.headers); | |
response.setEncoding('utf8'); | |
response.on('data', function(chunk) { | |
startupData += chunk; | |
}); | |
response.on('end', function() { | |
fs.writeFile('angellist_startup_' + startup_id + '.json', startupData, function (err) { | |
if (err) throw err; | |
console.log('It\'s saved!\n'); | |
}); | |
}); | |
}); | |
startupGet.end(); | |
startupGet.on('error', function(e) { | |
console.error(e); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment