Created
January 6, 2011 22:16
-
-
Save davidwhitney/768710 to your computer and use it in GitHub Desktop.
A quick Node.js example for accessing the JustGiving API
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 sys = require('sys'), http = require('http'); | |
| http.createServer(function (req, res) { | |
| var user = '[email protected]'; | |
| 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