npm install node-ral
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'
});
Every file in confDir will be loaded as config
// 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
{
"SOME_SERVICE": {
"unpack": "json",
"pack": "form",
"method": "POST"
"encoding": "gbk",
"balance": "random",
"protocol": "http",
"server": [
{ "host": "127.0.0.1", "port": 8080}
]
}
}
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
Future Feature
Internal Only
Complicate
- Base
- Config
- Balance
- Logger
- Converter
- Protocol
- RAL
- Filter
- Ext
- Balance
- RandomBalance
- RoundRobinBalance
- Filter
- ConnectFilter
- HealthFilter
- Converter
- JSON
- String
- Form
- QueryString
- Raw
- FormData
- Protobuf
- Msgpack
- Protocol
- HTTP
- HTTPS
- Socket
- Balance
- Issue
- Form unpack support GBK when use form-urlencoded
- Use Stream in Protocol
- Use Stream in Converter