0.0.3 • Published 5 years ago

jayrpc v0.0.3

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

JayRPC

JsonRPC server with middleware support.

Installation

npm install jayrpc

Simple usage

import JayRPC, { throwRPCError, ERRORS } from 'jayrpc';


class SimpleProcedure extends JayRPC.Procedure {
    static get name() {
        return 'Array.sum'
    }

    async call() {
        if (!Array.isArray(this.params)) {
            throwRPCError('Params can be array only', ERRORS.VALIDATION_ERROR);
        }
        return this.params.reduce((a, b) => a + b, 0)
    }
}


let server = JayRPC.Server('0.0.0.0', 8080, {
    rpcVersion: '2.0',
    errorClassToErrorCode: [
        [Error, ERRORS.INTERNAL_ERROR],
    ],
});

server.registerProcedure(SimpleProcedure);

server.listen();

How to make request to server

curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc": "2.0", "method": "Array.sum", "params": [1,2,3,4,5]}'
0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago