Active-Client
This library exists mainly to let HTTP clients treat various error codes correctly and not bundle
them under callbacks for success
, failure
etc. With active-client
, you can write better
clients such as the one below.
var client = require('active-client');
client.request({
method: 'POST',
uri: 'http://www.example.org/something,
body: 'param1=value¶m2=value2',
headers: {
'Content-Type' : 'application/x-www-form-urlencoded'
},
'401' : function(res) {
// Not authorized - do something about it
...
},
'4xx' : function(res) {
// Other 4xx errors
},
'5xx' : function(res) {
// Broken server?
...
},
'200' : function(res) {
// Handle 'on', 'data', 'end' etc on the res object as you would do with nodejs
res.on('data', function(chunk) {
...
});
res.on('end', function() {
...
});
}
});
That's all!
Use npm install active-client
to get active-client
.