1.1.3 • Published 9 months ago

vadimcontenthunter-jsonrpc-formatter v1.1.3

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

jsonrpc-formatter

A package for working with JSON-RPC 2.0. It automates the process of data formatting and supports all required fields and methods of the specification.

Features

  • Serialize JSON-RPC requests and responses.
  • Deserialize JSON-RPC responses.
  • Verify error objects and format error responses according to the JSON-RPC specification.

Installation

You can install the package using npm:

npm install vadimcontenthunter-jsonrpc-formatter

Usage

Serialize a JSON-RPC Request

const { JsonRpcFormatter } = require('jsonrpc-formatter');

const request = JsonRpcFormatter.serializeRequest("methodName", { param1: "value1" });
console.log(request);

Deserialize a JSON-RPC Response

const response = '{"jsonrpc":"2.0","result":{"data":"value"},"id":1}';
const parsedResponse = JsonRpcFormatter.deserializeResponse(response);
console.log(parsedResponse);

Format an Error Response

const errorResponse = JsonRpcFormatter.formatError(-32601, "Method not found", 1);
console.log(errorResponse);

Application Examples

  • Will be added later

License

This project is licensed under the MIT License. See the LICENSE file for details.

1.1.3

9 months ago

1.1.2

9 months ago

1.1.1

9 months ago

1.1.0

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago