https://github.com/blackglory/json-rpc-creator
π³ JSON-RPC 2.0 data structures creator
https://github.com/blackglory/json-rpc-creator
browser library nodejs npm-package typescript
Last synced: 2 months ago
JSON representation
π³ JSON-RPC 2.0 data structures creator
- Host: GitHub
- URL: https://github.com/blackglory/json-rpc-creator
- Owner: BlackGlory
- License: mit
- Created: 2018-12-01T05:46:01.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-06-11T04:05:35.000Z (about 3 years ago)
- Last Synced: 2025-02-15T22:29:19.979Z (over 1 year ago)
- Topics: browser, library, nodejs, npm-package, typescript
- Language: TypeScript
- Homepage:
- Size: 532 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# json-rpc-creator
JSON-RPC 2.0 data structures creator.
This module does not check types, nor convert unsupported types (e.g., `undefined` to `null`).
This is intentional so you can extend JSON-RPC to values ββother than JSON.
## Install
```sh
npm install --save json-rpc-creator
# or
yarn add json-rpc-creator
```
## API
### notification
```ts
function notification(method: string, params?: JsonRpcParams): JsonRpcNotification
function notification(obj: Omit, 'jsonrpc'>): JsonRpcNotification
```
### request
```ts
function request(id: JsonRpcId, method: string, params?: JsonRpcParams): JsonRpcRequest
function request(obj: Omit, 'jsonrpc'>): JsonRpcRequest
```
### success
```ts
function success(id: JsonRpcId, result: T): JsonRpcSuccess
function success(obj: Omit, 'jsonrpc'>): JsonRpcSuccess
```
### error
```ts
function error(id: JsonRpcId, code: number, message: string, data?: T): JsonRpcError
function error(id: JsonRpcId, error: JsonRpcErrorObject): JsonRpcError
function error(obj: Omit, 'jsonrpc'>): JsonRpcError
```
### batch
```ts
function batch(...requests: Array | JsonRpcNotification>): Array | JsonRpcNotification>
function batch(...responses: Array>): Array>
```