Skip to content

Instantly share code, notes, and snippets.

@davidwhitney
Created January 6, 2011 22:16
Show Gist options
  • Save davidwhitney/768710 to your computer and use it in GitHub Desktop.
Save davidwhitney/768710 to your computer and use it in GitHub Desktop.
A quick Node.js example for accessing the JustGiving API
var sys = require('sys'), http = require('http');
http.createServer(function (req, res) {
var user = 'david+publicexample@justgiving.com';
var password = 'password';
var auth = new Buffer(user + ':' + password).toString('base64');
var client = http.createClient(80, 'api.staging.justgiving.com', true);
var request = client.request('GET', '/decbf1d2/v1/fundraising/pages/nodejs-example/donations', {
'Host': 'api.staging.justgiving.com',
'Authorization': 'Basic ' + auth
});
request.addListener('response', function(apiResponse) {
var body = '';
apiResponse.addListener('data', function(chunk) {
body += chunk;
});
apiResponse.addListener('end', function() {
console.log(body);
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(body);
res.end();
});
});
request.end();
}).listen(8000);
sys.puts('Server running at http://127.0.0.1:8000/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment