JSPM

  • Created
  • Published
  • Downloads 839
  • Score
    100M100P100Q102234F
  • License BSD

a rpc client for node

Package Exports

  • node-ral
  • node-ral/lib/ctx

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-ral) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

node-ral

Build Status Coverage Status

Usage

Install

npm install node-ral

RAL init

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

// 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}
        ]
    }
}

Start a request

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

Support

  • Balance
    • RandomBalance
    • RoundRobinBalance
  • Converter
    • JSON
    • String
    • Form
    • QueryString
    • Raw
    • FormData
    • Stream
  • Protocol
    • HTTP
    • SOAP