Created
February 13, 2013 11:00
-
-
Save anonymous/4943862 to your computer and use it in GitHub Desktop.
Callback pattern for APIs
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
// inspiration: https://github.com/damienklinnert/appdotnet | |
var request = require('request'); | |
foo = function(cb) { | |
var opts = { uri: 'http://appd01:8111' }; | |
request.get(opts, function(err ,resp, body) { | |
if (err) { return cb(err); } | |
return cb(null, resp, body); | |
}); | |
}; | |
foo(function(err, response, body) { | |
if (err) { | |
console.log("error: %s", err); | |
} else { | |
console.log("status code: %s", response.statusCode); | |
console.log("body:\n %s", body); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment