modular-json-rcp
modular-json-rpc is a JSON-RPC 2.0 library.
Features:
- Simple transport interface allows easy addition of different transports (only ws transport is implemented at the moment)
- Supports bidirectional calls (see
RPCNode
) - Supports async calls and async server methods
- Written in typescript (has definitions)
Examples
Server-client RPC
Server code
const RPC = ;const WebSocket = ; const wss = port: 8080 ; wss; console;
Client code
const RPC = ;const WebSocket = ; const ws = 'ws://localhost:8080'; ws;
Client console output
$ node client.jsWebsocket connected.Calling method hello.Response: Hello, World!Calling method add.Response: 48
Bidirectional RPC
Node (ws server) code
const RPC = ;const WebSocket = ; const wss = port: 8080 ; wss; console;
Node (ws client) code
const RPC = ;const WebSocket = ; const ws = 'ws://localhost:8080'; ws;
Client console output
$ node node_client.jsWebsocket connected.Response: Hello, World!