All Projects → pocesar → node-jsonrpc2

pocesar / node-jsonrpc2

Licence: other
JSON-RPC 2.0 server and client library, with HTTP (with Websocket support) and TCP endpoints

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to node-jsonrpc2

Cowboy
Small, fast, modern HTTP server for Erlang/OTP.
Stars: ✭ 6,533 (+6242.72%)
Mutual labels:  https, websocket-server, websockets, http-server
Beetlex
high performance dotnet core socket tcp communication components, support TLS, HTTP, HTTPS, WebSocket, RPC, Redis protocols, custom protocols and 1M connections problem solution
Stars: ✭ 802 (+678.64%)
Mutual labels:  tcp, https, websocket-server, http-server
Jetty.project
Eclipse Jetty® - Web Container & Clients - supports HTTP/2, HTTP/1.1, HTTP/1.0, websocket, servlets, and more
Stars: ✭ 3,260 (+3065.05%)
Mutual labels:  https, websockets, http-server
Cppserver
Ultra fast and low latency asynchronous socket server & client C++ library with support TCP, SSL, UDP, HTTP, HTTPS, WebSocket protocols and 10K connections problem solution
Stars: ✭ 528 (+412.62%)
Mutual labels:  https, websocket-server, http-server
Netcoreserver
Ultra fast and low latency asynchronous socket server & client C# .NET Core library with support TCP, SSL, UDP, HTTP, HTTPS, WebSocket protocols and 10K connections problem solution
Stars: ✭ 799 (+675.73%)
Mutual labels:  https, websocket-server, http-server
remoting
Jetlang Remoting - asynchronous distributed messaging
Stars: ✭ 27 (-73.79%)
Mutual labels:  websocket-server, websockets, http-server
Kvpbase
Scalable, simple RESTful object storage platform, written in C#
Stars: ✭ 43 (-58.25%)
Mutual labels:  https, http-server, https-server
Restinio
Cross-platform, efficient, customizable, and robust asynchronous HTTP/WebSocket server C++14 library with the right balance between performance and ease of use
Stars: ✭ 694 (+573.79%)
Mutual labels:  https, websockets, http-server
Sish
HTTP(S)/WS(S)/TCP Tunnels to localhost using only SSH.
Stars: ✭ 2,087 (+1926.21%)
Mutual labels:  tcp, https, websockets
Getty
a netty like asynchronous network I/O library based on tcp/udp/websocket; a bidirectional RPC framework based on JSON/Protobuf; a microservice framework based on zookeeper/etcd
Stars: ✭ 532 (+416.5%)
Mutual labels:  tcp, websockets, json-rpc
cs
开箱即用的基于命令的消息处理框架,让 websocket 和 tcp 开发就像 http 那样简单
Stars: ✭ 19 (-81.55%)
Mutual labels:  tcp, websocket-server, http-server
Kvantum
An intellectual (HTTP/HTTPS) web server with support for server side templating (Crush, Apache Velocity and JTwig)
Stars: ✭ 17 (-83.5%)
Mutual labels:  https, http-server, https-server
Ixwebsocket
websocket and http client and server library, coming with ws, a command line swiss army knife utility
Stars: ✭ 204 (+98.06%)
Mutual labels:  websocket-server, websockets, http-server
Microwebsrv2
The last Micro Web Server for IoTs (MicroPython) or large servers (CPython), that supports WebSockets, routes, template engine and with really optimized architecture (mem allocations, async I/Os). Ready for ESP32, STM32 on Pyboard, Pycom's chipsets (WiPy, LoPy, ...). Robust, efficient and documented!
Stars: ✭ 295 (+186.41%)
Mutual labels:  https, websocket-server, websockets
Beast
HTTP and WebSocket built on Boost.Asio in C++11
Stars: ✭ 3,241 (+3046.6%)
Mutual labels:  websocket-server, websockets, http-server
Libhv
🔥 比libevent、libuv更易用的国产网络库。A c/c++ network library for developing TCP/UDP/SSL/HTTP/WebSocket client/server.
Stars: ✭ 3,355 (+3157.28%)
Mutual labels:  https, websocket-server, http-server
Ws Tcp Relay
A simple relay between WebSocket clients and TCP servers
Stars: ✭ 186 (+80.58%)
Mutual labels:  tcp, websocket-server, websockets
PuppyProxy
A simple HTTP proxy in C# including support for HTTP CONNECT tunneling
Stars: ✭ 37 (-64.08%)
Mutual labels:  https, http-server, https-server
text
An experiment with WebSockets and the human condition.
Stars: ✭ 51 (-50.49%)
Mutual labels:  websocket-server, websockets
jsonrpc2-zeromq-python
JSON-RPC 2.0 over ZeroMQ in Python
Stars: ✭ 52 (-49.51%)
Mutual labels:  json-rpc, json-rpc2

Build Status

NPM

node-jsonrpc2

JSON-RPC 2.0 server and client library, with HTTP (with Websocket support) and TCP endpoints

This fork is a rewrite with proper testing framework, linted code, compatible with node 0.8.x and 0.10.x, class inheritance, and added functionalities

Tools

Check jsonrpc2-tools for some nice additions to this module.

Install

To install node-jsonrpc2 in the current directory, run:

npm install json-rpc2 --save

Changes from 1.x

  • Uses native EventEmitter instead of EventEmitter3

Changes from 0.x

  • Before, the id member was permissive and wouldn't actually adhere to the RFC, allowing anything besides undefined.
  • If your application relied on weird id constructs other than String, Number or null, it might break if you update to 1.x

Usage

Firing up an efficient JSON-RPC server becomes extremely simple:

var rpc = require('json-rpc2');

var server = rpc.Server.$create({
    'websocket': true, // is true by default
    'headers': { // allow custom headers is empty by default
        'Access-Control-Allow-Origin': '*'
    }
});

function add(args, opt, callback) {
  callback(null, args[0] + args[1]);
}

server.expose('add', add);

// you can expose an entire object as well:

server.expose('namespace', {
    'function1': function(){},
    'function2': function(){},
    'function3': function(){}
});
// expects calls to be namespace.function1, namespace.function2 and namespace.function3

// listen creates an HTTP server on localhost only
server.listen(8000, 'localhost');

And creating a client to speak to that server is easy too:

var rpc = require('json-rpc2');

var client = rpc.Client.$create(8000, 'localhost');

// Call add function on the server

client.call('add', [1, 2], function(err, result) {
    console.log('1 + 2 = ' + result);
});

Create a raw (socket) server using:

var rpc = require('json-rpc2');

var server = rpc.Server.$create();

// non-standard auth for RPC, when using this module using both client and server, works out-of-the-box
server.enableAuth('user', 'pass');

// Listen on socket
server.listenRaw(8080, 'localhost');

Extend, overwrite, overload

Any class can be extended, or used as a mixin for new classes, since it uses ES5Class module.

For example, you may extend the Endpoint class, that automatically extends Client and Server classes. Extending Connection automatically extends SocketConnection and HttpServerConnection.

var rpc = require('json-rpc2');

rpc.Endpoint.$include({
    'newFunction': function(){

    }
});

var
    server = rpc.Server.$create(),
    client = rpc.Client.$create();

server.newFunction(); // already available
client.newFunction(); // already available

To implement a new class method (that can be called without an instance, like rpc.Endpoint.newFunction):

var rpc = require('json-rpc2');

rpc.Endpoint.$implement({
    'newFunction': function(){
    }
});

rpc.Endpoint.newFunction(); // available
rpc.Client.newFunction(); // every
rpc.Server.newFunction(); // where

Don't forget, when you are overloading an existing function, you can call the original function using $super

var rpc = require('json-rpc2');

rpc.Endpoint.$implement({
    'trace': function($super, direction, message){
        $super(' (' + direction + ')', message); //call the last defined function
    }
});

And you can start your classes directly from any of the classes

var MyCoolServer = require('json-rpc2').Server.$define('MyCoolServer', {
    myOwnFunction: function(){
    },
}, {
    myOwnClassMethod: function(){
    }
}); // MyCoolServer will contain all class and instance functions from Server

MyCoolServer.myOwnClassMethod(); // class function
MyCoolServer.$create().myOwnFunction(); // instance function

Debugging

This module uses the debug package, to debug it, you need to set the Node environment variable to jsonrpc, by setting it in command line as set DEBUG=jsonrpc or export DEBUG=jsonrpc

Examples

To learn more, see the examples directory, peruse test/jsonrpc-test.js, or simply "Use The Source, Luke".

More documentation and development is on its way.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].