Comparing version 0.0.5 to 0.0.6
@@ -10,3 +10,3 @@ /* | ||
var Converter = require('../../converter.js'); | ||
var UrlEncodeConverter = require('./urlencodeConverter.js'); | ||
var FormConverter = require('./fromConverter.js'); | ||
var logger = require('../../logger.js')('QuertStringConverter'); | ||
@@ -23,3 +23,3 @@ var util = require('util'); | ||
QuertStringConverter.prototype.unpack = UrlEncodeConverter.prototype.unpack; | ||
QuertStringConverter.prototype.unpack = FormConverter.prototype.unpack; | ||
@@ -26,0 +26,0 @@ QuertStringConverter.prototype.pack = function (config, data) { |
{ | ||
"name": "node-ral", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "a rpc client for node", | ||
@@ -28,5 +28,3 @@ "main": "index.js", | ||
"chai": "1.9.1", | ||
"combined-stream": "0.0.5", | ||
"form-data": "0.1.4", | ||
"formidable": "1.0.15", | ||
"iconv-lite": "0.4.4", | ||
@@ -40,6 +38,8 @@ "performance-now": "0.1.3", | ||
"devDependencies": { | ||
"combined-stream": "0.0.5", | ||
"istanbul": "0.3.0", | ||
"mocha": "1.21.3", | ||
"should": "4.0.4" | ||
"should": "4.0.4", | ||
"formidable": "1.0.15" | ||
} | ||
} |
@@ -7,2 +7,88 @@ node-ral | ||
## Usage | ||
### Install | ||
```bash | ||
npm install node-ral | ||
``` | ||
### RAL init | ||
```javascript | ||
var RAL = require('node-ral').RAL; | ||
RAL.init({ | ||
//path to config files | ||
confDir : __dirname + path.sep + './config', | ||
logger : { | ||
"log_path" : __dirname + path.sep + '../logs' | ||
}, | ||
//specify the server's idc, ral will priority use backend with same idc | ||
currentIDC : 'tc' | ||
}); | ||
``` | ||
### config file | ||
Every file in confDir will be loaded as config | ||
```javascript | ||
// config/config.js | ||
module.exports = { | ||
'SOME_SERVICE': { | ||
unpack: 'json', | ||
pack: 'form', | ||
method: 'POST' | ||
encoding: 'gbk', | ||
balance: 'random', | ||
protocol: 'http', | ||
retry: 2, | ||
timeout: 500, | ||
server: [ | ||
{ host: '127.0.0.1', port: 8080} | ||
] | ||
} | ||
}; | ||
``` | ||
Also support json config file | ||
```json | ||
{ | ||
"SOME_SERVICE": { | ||
"unpack": "json", | ||
"pack": "form", | ||
"method": "POST" | ||
"encoding": "gbk", | ||
"balance": "random", | ||
"protocol": "http", | ||
"server": [ | ||
{ "host": "127.0.0.1", "port": 8080} | ||
] | ||
} | ||
} | ||
``` | ||
### Start a request | ||
```javascript | ||
var RAL = require('node-ral').RAL; | ||
var request = RAL('SOME_SERVICE', { | ||
path: '/user/info' | ||
data: { | ||
'name': 'hefangshi', | ||
'city': 'Beijing', | ||
'gender': 'Male' | ||
} | ||
}); | ||
request.on('data', function(data){ | ||
data.status.should.be.eql(0); | ||
}); | ||
``` | ||
more usage can be found in /test/ral.js | ||
## TODO | ||
@@ -34,6 +120,6 @@ | ||
- [X] String | ||
- [X] UrlEncode | ||
- [X] Form | ||
- [X] QueryString | ||
- [X] Raw | ||
- [X] **Form** | ||
- [X] **FormData** | ||
- [ ] *Protobuf* | ||
@@ -40,0 +126,0 @@ - [ ] *Msgpack* |
@@ -13,5 +13,5 @@ /* | ||
var StringConverter = require('../lib/ext/converter/stringConverter.js'); | ||
var FormConverter = require('../lib/ext/converter/formConverter.js'); | ||
var FormDataConverter = require('../lib/ext/converter/formDataConverter.js'); | ||
var HttpProtocol = require('../lib/ext/protocol/httpProtocol.js'); | ||
var UrlEncodeConverter = require('../lib/ext/converter/urlencodeConverter.js'); | ||
var FormConverter = require('../lib/ext/converter/fromConverter.js'); | ||
var QueryStringConverter = require('../lib/ext/converter/querystringConverter.js'); | ||
@@ -171,10 +171,10 @@ var RawConverter = require('../lib/ext/converter/rawConverter.js'); | ||
describe('form converter', function () { | ||
describe('formdata converter', function () { | ||
it('has right name', function () { | ||
var converter = new FormConverter(); | ||
converter.getName().should.be.equal('form'); | ||
var converter = new FormDataConverter(); | ||
converter.getName().should.be.equal('formdata'); | ||
}); | ||
it('has right catagory', function () { | ||
var converter = new FormConverter(); | ||
var converter = new FormDataConverter(); | ||
converter.getCategory().should.be.equal('converter'); | ||
@@ -184,3 +184,3 @@ }); | ||
it('pack should work fine', function (done) { | ||
var converter = new FormConverter(); | ||
var converter = new FormDataConverter(); | ||
var data = { | ||
@@ -212,3 +212,3 @@ name: '张三李四' | ||
it('pack gbk correctly', function (done) { | ||
var converter = new FormConverter(); | ||
var converter = new FormDataConverter(); | ||
var data = { | ||
@@ -240,3 +240,3 @@ name: '张三李四' | ||
it('pack should fail if encoding is illegal', function () { | ||
var converter = new FormConverter(); | ||
var converter = new FormDataConverter(); | ||
var data = { | ||
@@ -251,3 +251,3 @@ name: "hefangshi" | ||
it('pack should work if data is null', function () { | ||
var converter = new FormConverter(); | ||
var converter = new FormDataConverter(); | ||
var data = null; | ||
@@ -260,10 +260,10 @@ (function () { | ||
describe('urlencode converter', function () { | ||
describe('form converter', function () { | ||
it('has right name', function () { | ||
var converter = new UrlEncodeConverter(); | ||
converter.getName().should.be.equal('urlencode'); | ||
var converter = new FormConverter(); | ||
converter.getName().should.be.equal('form'); | ||
}); | ||
it('has right catagory', function () { | ||
var converter = new UrlEncodeConverter(); | ||
var converter = new FormConverter(); | ||
converter.getCategory().should.be.equal('converter'); | ||
@@ -273,3 +273,3 @@ }); | ||
it('pack and unpack should be paired', function () { | ||
var converter = new UrlEncodeConverter(); | ||
var converter = new FormConverter(); | ||
var data = { | ||
@@ -285,3 +285,3 @@ a: 1, | ||
it('pack and unpack gbk correctly', function () { | ||
var converter = new UrlEncodeConverter(); | ||
var converter = new FormConverter(); | ||
var data = { | ||
@@ -298,3 +298,3 @@ a: 1, | ||
it('pack should work if data is null', function () { | ||
var converter = new UrlEncodeConverter(); | ||
var converter = new FormConverter(); | ||
var data = null; | ||
@@ -307,3 +307,3 @@ (function () { | ||
it('pack should work fine', function (done) { | ||
var converter = new UrlEncodeConverter(); | ||
var converter = new FormConverter(); | ||
var data = { | ||
@@ -357,3 +357,3 @@ name: '张三李四' | ||
var converter = new QueryStringConverter(); | ||
var urlencodeConverter = new UrlEncodeConverter(); | ||
var urlencodeConverter = new FormConverter(); | ||
var data = { | ||
@@ -360,0 +360,0 @@ a: 1, |
@@ -21,3 +21,3 @@ /* | ||
RalModule.modules.converter.string.should.be.ok; | ||
RalModule.modules.converter.urlencode.should.be.ok; | ||
RalModule.modules.converter.formdata.should.be.ok; | ||
@@ -24,0 +24,0 @@ RalModule.modules.protocol.http.should.be.ok; |
Sorry, the diff of this file is too big to display
8
132
222606
5
+ Addedcombined-stream@0.0.7(transitive)
- Removedcombined-stream@0.0.5
- Removedformidable@1.0.15
- Removedcombined-stream@0.0.5(transitive)
- Removedformidable@1.0.15(transitive)