# noice-json-rpc

> Noice Json RPC exposes a clean ES6 Proxy and Promise based interface for JSON-RPC2 Clients and Servers

Latest version **1.2.0** (published 2018-05-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install noice-json-rpc
pnpm add noice-json-rpc
yarn add noice-json-rpc
bun add noice-json-rpc
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2018-05-02 |
| First published | 2016-07-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 27.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 46 |
| Author | nojvek |
| Maintainers | nojvek |
| Keywords | noice, json, rpc, rpc2, es6, proxy, promises, api, server, client |

## Links

- npm: https://www.npmjs.com/package/noice-json-rpc
- Repository: https://github.com/nojvek/noice-json-rpc
- Homepage: https://github.com/nojvek/noice-json-rpc#readme
- Issues: https://github.com/nojvek/noice-json-rpc/issues
- npm.io page: https://npm.io/package/noice-json-rpc

## 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.2.0 (latest) — 2018-05-02
- 1.1.2 — 2018-04-04
- 1.1.1 — 2017-12-07
- 1.1.0 — 2017-10-31
- 1.0.2 — 2017-07-22
- 1.0.1 — 2017-02-22
- 1.0.0 — 2016-07-24
- 0.2.0 — 2016-07-22
- 0.1.0 — 2016-07-22
- 0.0.1 — 2016-07-21

## README

# Noice Json Rpc
[![Build Status](https://img.shields.io/travis/nojvek/noice-json-rpc/master.svg)](https://travis-ci.org/nojvek/noice-json-rpc)
[![Coverage Status](https://img.shields.io/coveralls/nojvek/noice-json-rpc/master.svg)](https://coveralls.io/github/nojvek/noice-json-rpc?branch=master)
[![issues open](https://img.shields.io/github/issues/nojvek/noice-json-rpc.svg)](https://github.com/nojvek/noice-json-rpc/issues)
[![npm total downloads](https://img.shields.io/npm/dt/noice-json-rpc.svg?maxAge=2592000)](https://www.npmjs.com/package/noice-json-rpc)
[![licence](https://img.shields.io/npm/l/noice-json-rpc.svg?maxAge=2592000)](https://github.com/nojvek/noice-json-rpc)
[![npm version](https://img.shields.io/npm/v/noice-json-rpc.svg)](https://www.npmjs.com/package/noice-json-rpc)

Client and Server helpers to implement a clean function based Api for Json Rpc.

Noice Json Rpc takes in a websocket like object. It calls `send(msg:str)` function and expects messages to come from `on('message', handler)`. It works out of the box with WebSockets but it can also work with stdin/stdout, worker threads, iframes or any other mechanism in which strings can be sent or received.

Its only dependency is `events.EventEmitter`.

Using ES6 proxies it exposes a clean client-server api. Since its written in TypeScript, the api object can be cast to work off an interface specific to the domain. e.g [ChromeDevTools/devtools-protocol](https://github.com/ChromeDevTools/devtools-protocol/blob/master/types/protocol.d.ts)

## [Example](tests/example.ts)

```js
import * as WebSocket from 'ws'
import DevToolsProtocol from 'devtools-protocol'
import * as rpc from '../lib/noice-json-rpc'

async function setupClient() {
    try {
        const rpcClient = new rpc.Client(new WebSocket('ws://localhost:8080'), {logConsole: true})
        const api: DevToolsProtocol.ProtocolApi = rpcClient.api()

        await Promise.all([
            api.Runtime.enable(),
            api.Profiler.enable(),
        ])

        await api.Runtime.run()
        await api.Profiler.start()
        await new Promise(resolve => api.Runtime.on('executionContextDestroyed', resolve)); // Wait for event
        const result = await api.Profiler.stop()

        console.log('Result', result)

    } catch (e) {
        console.error(e)
    }
}

setupClient()
```

Output

```
Client > {"id":1,"method":"Runtime.enable"}
Client > {"id":3,"method":"Profiler.enable"}
Client > {"id":4,"method":"Runtime.run"}
Client < {"id":1,"result":{}}
Client < {"id":2,"result":{}}
Client < {"id":3,"result":{}}
Client < {"id":4,"result":{}}
Client > {"id":5,"method":"Profiler.start"}
Client < {"id":5,"result":{}}
Client < {"method":"Runtime.executionContextDestroyed"}
Client > {"id":6,"method":"Profiler.stop"}
Client < {"id":6,"result":{"data":"noice!"}}
```

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