1.3.0 • Published 1 year ago

s4o-js-tools v1.3.0

Weekly downloads
3
License
ISC
Repository
-
Last release
1 year ago

A node based JSON-RPC 2.0 server stub

JSON-RPC specification

  • Uses node http currently to handle requests
  • Includes method params validation
  • Take a look at the example folder for implementation guide

Type Structure

{
  TypeName: {
    description: 'description of type',
    schema: {
      prop1: { type: Number },
      prop2: { type: String },
      ...
    }
  },
  ...
}
  • TypeName should be capitalized
  • schema follows structure from validate

Method Structure

{
  methodName: {
    description: 'method description',
    params: ['Type1',...],
    returns: ['Type2',...],
    exec: async (data) => {
      ...
    }
  },
  ...
}
  • Types can be defined as in validate
  • Types can as well be primitives such as
Number, String, Boolean, Array, Object
  • TODO: treat array types with
Array<Type>

Usage

let http = require('http');

let RPC = require('rpc_stub');
// your methods
let methods = require('./methods');
// your types
let types = require('./types');
// authenticate
let authenticate = async (req) => {
  // request authentication code
}

let handler = new RPC(types, methods, authenticate); 
let server = http.createServer(handler.getListener());
const PORT = process.env.PORT || 9090;

server.listen(PORT);
console.log('listening on port',PORT);

TODO

  • Add parameter validation
  • Add Unit Tests
  • Add Response Validation
  • Add access control
1.1.1

2 years ago

1.3.0

1 year ago

1.1.2

2 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.1

4 years ago

1.0.0

4 years ago