An open API service indexing awesome lists of open source software.

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

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>
```