# @happapi/jsonrpc-core

> A simple implementation of jsonrpc2

Latest version **1.0.6** (published 2020-08-18) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @happapi/jsonrpc-core
pnpm add @happapi/jsonrpc-core
yarn add @happapi/jsonrpc-core
bun add @happapi/jsonrpc-core
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2020-08-18 |
| First published | 2020-08-08 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 290.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | tianlin |
| Maintainers | wangtianlin |
| Keywords | jsonrpc |

## Links

- npm: https://www.npmjs.com/package/@happapi/jsonrpc-core
- Repository: https://github.com/tianlinle/jsonrpc
- Homepage: https://github.com/tianlinle/jsonrpc#readme
- Issues: https://github.com/tianlinle/jsonrpc/issues
- npm.io page: https://npm.io/package/@happapi/jsonrpc-core

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.6 (latest) — 2020-08-18
- 1.0.5 — 2020-08-09
- 1.0.4 — 2020-08-08
- 1.0.3 — 2020-08-08
- 1.0.1 — 2020-08-08

## README

# jsonrpc
A simple implementation of jsonrpc2

### example

```js
const { JsonRpcHandler, JsonRpcError } = require('tian-jsonrpc');

let jsonRpc = new JsonRpcHandler();

//add a single method like this...
jsonRpc.setMethodHandler('sayHello', function ({ name }) {
    if (!name) {
        throw JsonRpcError.InvalidParams('parameter `name` is required');
    }
    return `hello ${name}`;
});

//now you can handle jsonrpc request
jsonRpc.handle('{"jsonrpc":"2.0","method":"doSomething","id":"1"}');

//await to get result
(async () => {
    let result2 = await jsonRpc.handle([
        { jsonrpc: '2.0', method: 'unexisted method', id: 1 },
        { jsonrpc: '2.0', method: 'sayHello', id: 2, params: { name: 'world' } }
    ]);
})();
```

### api
+ JsonRpcError
JsonRpcError.constructor(code, message, data?)
    + JsonRpcError.toJSON()
    + JsonRpcError.ParseError.constructor(data?)
    + JsonRpcError.InvalidRequest.constructor(data?)
    + JsonRpcError.MethodNotFound.constructor(data?)
    + JsonRpcError.InvalidParams.constructor(data?)
    + JsonRpcError.InternalError.constructor(data?)
+ JsonRpcResult
    + static JsonRpcResult.success(id, result)
    + static JsonRpcResult.error(id, error)
+ JsonRpcHandler
    + JsonRpcHandler.constructor()
    + JsonRpcHandler.setMethodHandler(method: string, handler: Function, context?: Object)
    + async JsonRpcHandler.handle(body)

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