# jayrpc

> JsonRPC server with middleware support

Latest version **0.0.3** (published 2019-10-01) · ISC license · 0 weekly downloads

## Install

```sh
npm install jayrpc
pnpm add jayrpc
yarn add jayrpc
bun add jayrpc
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2019-10-01 |
| First published | 2019-09-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 2 |
| Unpacked size | 46.7 KB |
| Known vulnerabilities | 0 (+3 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Mikhail Trifonov |
| Maintainers | trifonovmixail |
| Keywords | jsonrpc, rpc, json |

## Links

- npm: https://www.npmjs.com/package/jayrpc
- Repository: https://github.com/trifonovmixail/jayrpc
- Homepage: https://github.com/trifonovmixail/jayrpc#readme
- Issues: https://github.com/trifonovmixail/jayrpc/issues
- npm.io page: https://npm.io/package/jayrpc

## Dependencies (2)

- [ajv](https://npm.io/package/ajv.md) 6.10.2
- [http](https://npm.io/package/http.md) 0.0.0

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

- 0.0.3 (latest) — 2019-10-01
- 0.0.2 — 2019-09-27

## README

# JayRPC

JsonRPC server with middleware support.

## Installation

```bash
npm install jayrpc
```

## Simple usage

```javascript
import JayRPC, { throwRPCError, ERRORS } from 'jayrpc';


class SimpleProcedure extends JayRPC.Procedure {
    static get name() {
        return 'Array.sum'
    }

    async call() {
        if (!Array.isArray(this.params)) {
            throwRPCError('Params can be array only', ERRORS.VALIDATION_ERROR);
        }
        return this.params.reduce((a, b) => a + b, 0)
    }
}


let server = JayRPC.Server('0.0.0.0', 8080, {
    rpcVersion: '2.0',
    errorClassToErrorCode: [
        [Error, ERRORS.INTERNAL_ERROR],
    ],
});

server.registerProcedure(SimpleProcedure);

server.listen();
```

How to make request to server

```bash
curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc": "2.0", "method": "Array.sum", "params": [1,2,3,4,5]}'
```

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