0.4.4 • Published 6 years ago

jsonrpc2-express v0.4.4

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
6 years ago

jsonrpc2-express: JSON-RPC end-point for express

build status

Module to configure an express router in order to expose a JSON-RPC end-point.

Installation

npm install jsonrpc2-express

Usage

const express = require('express');
const jsonrpc = require('jsonrpc2-express')

const app = express();

let routerRpc = express.Router();

jsonrpc('/rpc/module1', routerRpc, {
    methods: require('./module1.js'),
    bodyParser: {
        limit: '50mb'
    }
});

app.use('/api', routerRpc);

app.listen(3000, function() {
    console.log('Server listening on port 3000');
});

The file module1.js with the implementation of the different methods is:

exports.f1 = function(req) {
	console.log(req.body.params)
    return {
	field1: 'answer from f1',
	user: req.user
    };
};

exports.f2 = function(req) {
	console.log(req.body.params)
    return {
	field1: 'answer from f2',
	user: req.user
    };
};

exports.ferror = function(req) {
    throw new Error("sorry");
};

The parameters for each method can be read from req.body.params

Tests

npm test

Contributing

In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.

0.4.4

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago