@adt/json-rpc

0.0.1-SNAPSHOT.27 • Public • Published

JsonRpc npm version Build Status

Base JsonRpc classes. Represents all elements from JSON-RPC 2.0 specification http://www.jsonrpc.org/specification

Values that can be omitted, by default are set to undefined.

Specification says, that params in request can be ommited, but omitting property in object is not a good practice. Therefore, request and event object "params" property always exists, but can be set to value "undefined". When params property is undefined it will not be serialized.

Install

npm install @adt/json-rpc or yarn add @adt/json-rpc

Usage

import { JsoRpcEvent, JsonRpcRequest } from "@adt/json-rpc"

const byeEvent = JsonRpcEvent({
    method: "Bye",
    params:{
        name: "Joe"
    }
});

console.log(byeEvent.serialize());

const helloRequest = JsonRpcRequest({
    method: "Hello",
    params: {
        name: "Joe";
    }
});

console.log(helloRequest.serialize());

const helloRequestWithExplicitId = JsonRpcRequest({
    id: 1,
    method: "Hello",
    params: {
        name: "Joe";
    }
});

console.log(helloRequestWithExplicitId.serialize());

For more use cases please look at test specs.

Why i should use Json-RPC?

TODO :)

When i can use Json-RPC?

TODO :)

Package Sidebar

Install

npm i @adt/json-rpc

Weekly Downloads

4

Version

0.0.1-SNAPSHOT.27

License

MIT

Unpacked Size

52.2 kB

Total Files

7

Last publish

Collaborators

  • adt