jisson-rpc

JSON-RPC server object oriented

npm install jisson-rpc
7 downloads in the last month

Jissonrpc

JissonRPC is a JSON-RPC 2.0 server as a middleware to use with Express.js.

Features

  • Basic implementation of JSON-RPC 2.0 specification on server side
  • Works as a middleware with Express.js
  • Batch multi requests
  • Structure of request as object oriented controllers and actions
  • Give access to request and response into action methods

Example

See Express example

Changelog

  • 0.0.1 : Initial release

Requirements

Just call npm install.

Running tests

Just run npm test.

Usage

Just add the jissonrpc server as a middleware in your express app. You can specify the folder where your services are located as a config object params :

app.use('/api', jissonrpc({services: 'the path'}))

Your services must be called with a simple alphanumerical name with just letters and numbers. Example : test.js.

Theses services must implement a class (function with prototype) which contains your API methods as methodnameMethod. Example : testMethod.

Example for the method user.get, you will have a file named user.js with this content :

var UserService = function(){};
UserService.prototype = {
    getMethod: function(params, callback/*(error, result)*//*, req, res*/)
    {

    }
}
module.exports = UserService;

For each of your methods, you'll have access to four parameters :

  • params : is the params object sent by the client
  • callback : is the callback to call when you finished your process. It take two params : first is an error object, second is a result object.
  • req : is the request object from the http server. You shouldn't have to use it, but you have it if needed
  • res : is the response object from the http server. Same advice as req, use it only if you have to send a very specific response.
npm loves you