μRPC v5
Transport agnostic bidirectional JsonRPC 1.0 implementation for browser and node.js.
Install
Install via npm:
npm i urpc
Import in browser:
<!-- UMD -->
And then use in some script:
Single-file ESM and CommonJS versions are also distributed with a build.
Usage
Hello world example. This is a simple endpoint which provide single
method greet(name)
, which returns a greeting message as a result.
; { if reqmethod === 'greet' resresult = `Hello, !`; }; // Create listening (server) connection with custom serverwsServer;
Codecs
By default all messages passed in or out of a connection is encoded and decoded via built-in default codec (which is JSON). But you may use no codec:
; const rpc = codec: null // no codec;
Or define another codec:
;; const cborCodec = { return CBOR } { return CBOR }; const rpc = codec: cborCodec;
License
MIT © Rumkin