# koa-jsonrpc

> Json RPC 2 middleware implementation on Koa v2

Latest version **1.1.1** (published 2018-02-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install koa-jsonrpc
pnpm add koa-jsonrpc
yarn add koa-jsonrpc
bun add koa-jsonrpc
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2018-02-14 |
| First published | 2018-01-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 15.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | unibtc@gmail.com |
| Maintainers | unibtc |
| Keywords | koa, json-rpc, rpc |

## Links

- npm: https://www.npmjs.com/package/koa-jsonrpc
- Repository: https://github.com/Bitclimb/koa-jsonrpc
- Homepage: https://github.com/Bitclimb/koa-jsonrpc#readme
- Issues: https://github.com/Bitclimb/koa-jsonrpc/issues
- npm.io page: https://npm.io/package/koa-jsonrpc

## Dependencies (1)

- [co-body](https://npm.io/package/co-body.md) ^5.1.1

## 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.1.1 (latest) — 2018-02-14
- 1.1.0 — 2018-02-14
- 1.0.0 — 2018-01-01

## README

# koa-jsonrpc
Json-RPC 2 middleware implementation on Koa v2

## Requirements
- Koa@2+
- Node@8+


## Installation
```js
npm install koa-jsonrpc --save
```

## Options

- limit[String] - sets the maximum size allowed for requests
- auth[Object] - requires requests to have a valid HMAC256 of the username and password as its authorization header

## Authorization
```js
//generating authorization header
const crypto = require('crypto');
const token = crypto.createHmac('sha256','mypass').update('myuser').digest('hex')
console.log(token) // will print out the token, and you can add this on the header of your request.
```

## Usage
```js
const Koa = require('koa');
const app = new Koa();
const koaJsonRpc = require('koa-jsonrpc');
const options = {
  limit: '20mb', // optional, defaults to 1mb
  auth: { // optional, will require authorization header
    username: 'myuser',
    password: 'mypass'
  }
}
const jrpc2 = koaJsonRpc(options);

// Add methods
jrpc2.use('user', async function user() {
  return 'root';
});

jrpc2.use('sum', async function sum(params) {
  return params.reduce((prev, curr) => prev + curr,
        0);
});

jrpc2.use('internal', async function internal() {
  throw new Error();
});

app.use(jrpc2.app());
```

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