# @erebos/rpc-base

> Base RPC class

Latest version **0.10.0** (published 2019-10-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @erebos/rpc-base
pnpm add @erebos/rpc-base
yarn add @erebos/rpc-base
bun add @erebos/rpc-base
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.10.0 |
| Published | 2019-10-01 |
| First published | 2019-10-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 4 KB |
| Known vulnerabilities | 0 (+4 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 48 |
| Author | Mainframe |
| Maintainers | sarahwiley, mosic, howleysv, aclarke, diogoperillo, paul_lecam |

## Links

- npm: https://www.npmjs.com/package/@erebos/rpc-base
- Repository: https://github.com/MainframeHQ/erebos
- Homepage: https://github.com/MainframeHQ/erebos#readme
- Issues: https://github.com/MainframeHQ/erebos/issues
- npm.io page: https://npm.io/package/@erebos/rpc-base

## Dependencies (2)

- [nanoid](https://npm.io/package/nanoid.md) ^2.1.1
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.6.2

## Recent versions

- 0.10.0 (latest) — 2019-10-01

## README

# rpc-base

Abstract class to handle JSON-RPC 2.0 calls, used by [`rpc-request`](../rpc-request) and [`rpc-stream`](../rpc-stream).

## Installation

```sh
yarn add @erebos/rpc-base
```

## Usage

```js
import BaseRPC from '@erebos/rpc-base'

class MyRPC extends BaseRPC {
  request(...params: any): Promise<any> {
    // ...
  }
}
```

## Types

### RPCID

```js
type RPCID = string | number | null
```

### RPCRequest

```js
interface RPCRequest<T = any> {
  jsonrpc: '2.0'
  method: string
  id?: RPCID
  params?: T
}
```

### RPCError

```js
interface RPCErrorObject<T = any> {
  code: number;
  message?: ?string;
  data?: T;
}
```

### RPCResponse

```js
interface RPCResponse<T = any, E = any> {
  jsonrpc: '2.0';
  id: RPCID;
  result?: T;
  error?: RPCErrorObject<E>;
}
```

## API

### new BaseRPC()

**Arguments**

1.  `canSubscribe: boolean = false`: whether subscription calls (using a stateful connection) are supported by the implementation or not.

### .canSubscribe

**Returns** `boolean`

### .createId()

**Returns** `string`: an unique ID for RPC calls.

### .request()

**⚠️ This is an abstract method, it must be implemented by extending classes**\

**Arguments**

1. `method: string`
1. `params?: P`

**Returns** `Promise<T = any>`

## License

MIT

---
_Source: https://npm.io/package/@erebos/rpc-base · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
