mschema-rpc
Minimalistic Remote Procedural Call library using mschema validation for remote method's input and output.
Last updated 10 years ago by marak .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install mschema-rpc 
SYNC missed versions from official npm registry.

mschema-rpc

Minimalistic Remote Procedural Call library using mschema validation for remote method's input and output.

Features

  • Provides validation to functions incoming arguments and outgoing results
  • Validation based on mschema

API

rpc.invoke(inputData, method, methodSchema, callback)

inputData

the input data to be sent to method

method

the method to be executed remotely

methodSchema

the schema to be used to validate the input and output of method

schema format

{
  "input": {
    "key": "val"
  },
  "output": {
    "key": "val"
  }
}

see: http://github.com/mschema/mschema for full schema format documentation

callback

the callback to be executed after method has been invoked

Example


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);
});

Current Tags

  • 0.7.0                                ...           latest (10 years ago)

4 Versions

  • 0.7.0                                ...           10 years ago
  • 0.6.0                                ...           11 years ago
  • 0.5.1                                ...           13 years ago
  • 0.5.0                                ...           13 years ago
Maintainers (1)
Downloads
Total 8
Today 0
This Week 0
This Month 4
Last Day 0
Last Week 3
Last Month 1
Dependencies (1)
Dev Dependencies (1)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE