Minimalistic Remote Procedural Call library using mschema validation for remote method's input and output.
npm install mschema-rpcMinimalistic Remote Procedural Call library using mschema validation for remote method's input and output.
- Provides validation to functions incoming arguments and outgoing results
- Validation based on mschema
methodmethodschema format
``json`
{
"input": {
"key": "val"
},
"output": {
"key": "val"
}
}
see: http://github.com/mschema/mschema for full schema format documentation
the callback to be executed after method has been invoked
`js
var rpc = require('mschema-rpc');
var fireSchema = {
"description": "fires missle",
"input": {
"name": "string",
"power": {
"type": "string",
"enum": ["high", "medium", "low"]
},
"warheads": {
"type": "number",
"min": 1,
"max": 8
}
},
"output": {
"result": "string"
}
};
function fireFn (input, callback) {
callback(null, 'weapon fired');
}
var data = {
"name": "small missle",
"power": "low",
"warheads": 8
};
rpc.invoke(data, fireFn, fireSchema, function(errors, result) {
console.log('errors', errors);
console.log('result', result);
});
``