Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including jisson-rpc with all npm packages installed. Try it out:

var jissonRpc = require("jisson-rpc")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

jisson-rpc v0.0.2

JSON-RPC server object oriented

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.

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free