node-rest-client
Advanced tools
Comparing version 0.0.1 to 0.0.2
var http = require('http'), | ||
https = require('https'), | ||
parseString = require('xml2js').parseString, | ||
urlParser = require('url'); | ||
urlParser = require('url'), | ||
util = require("util"); | ||
events = require("events"); | ||
@@ -15,4 +17,3 @@ | ||
this.methods={}; | ||
var Util = { | ||
@@ -185,2 +186,8 @@ | ||
}; | ||
// handle ConnectManager events | ||
ConnectManager.on('error',function(err){ | ||
self.emit('error',err); | ||
}); | ||
}; | ||
@@ -258,4 +265,3 @@ | ||
proxyTunnel.on('error',function(e){ | ||
console.error(e); | ||
throw e; | ||
self.emit('error',e); | ||
}); | ||
@@ -296,3 +302,3 @@ | ||
request.on('error',function(e){ | ||
console.error(e); | ||
self.emit('error',e); | ||
}); | ||
@@ -308,2 +314,8 @@ debug("options data", options.data); | ||
// event handlers for client and ConnectManager | ||
util.inherits(exports.Client, events.EventEmitter); | ||
util._extend(ConnectManager,events.EventEmitter.prototype); | ||
var debug = function(){ | ||
@@ -319,2 +331,3 @@ if (!process.env.DEBUG) return; | ||
}; | ||
}; | ||
{ | ||
"author": { | ||
"name": "Alejandro Alvarez Acero" | ||
}, | ||
"author": "Alejandro Alvarez Acero", | ||
"name": "node-rest-client", | ||
"description": "node API REST client", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"repository": { | ||
"type": "git", | ||
"type":"git", | ||
"url": "https://github.com/aacerox/node-rest-client.git" | ||
}, | ||
"main": "./lib/node-rest-client", | ||
"main": "./lib/node-rest-client", | ||
"dependencies": { | ||
"xml2js": ">=0.2.4" | ||
}, | ||
"xml2js":">=0.2.4" | ||
}, | ||
"devDependencies": { | ||
"jasmine-node": ">=1.2.3" | ||
}, | ||
"jasmine-node":">=1.2.3" | ||
}, | ||
"optionalDependencies": {}, | ||
@@ -23,2 +21,2 @@ "engines": { | ||
} | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# Node REST Client for Node.js | ||
# REST Client for Node.js | ||
@@ -227,2 +227,16 @@ Allows connecting to any API REST and get results as js Object. The client has the following features: | ||
``` | ||
### Error Handling | ||
Client can emits error events that can be handled like usually node does. | ||
```javascript | ||
client = new Client(options_auth); | ||
client.on('error',function(err){ | ||
console.error('Something went wrong', err); | ||
}); | ||
``` |
@@ -9,3 +9,3 @@ var Client = require('../lib/node-rest-client.js').Client; | ||
password:"nostromo73" | ||
}, | ||
}, | ||
user:"acero", | ||
@@ -28,7 +28,8 @@ password:"nostromo" | ||
var client = new Client(default_config), | ||
args = null; | ||
args = {}; | ||
client.registerMethod("testJson", "http://127.0.0.1:4444/json", "GET"); | ||
client.registerMethod("testJson", "http://127.0.0.1:4445/json", "GET"); | ||
client.methods.testJson(null,null,function(data){ | ||
client.methods.testJson(function(data){ | ||
console.log(data); | ||
@@ -39,8 +40,10 @@ | ||
client.get("http://localhost:4444/json",null,function(data){ | ||
client.get("http://localhost:4444/json",function(data){ | ||
console.log(data); | ||
}); | ||
client.on('error',function(err){ | ||
console.error("error desde evento",err); | ||
}); |
29842
12
628
241