# json-rpc2.0-node

> A simple and extendable json-rpc-2.0 implementation, include server and client, written by typescript

Latest version **2.0.4** (published 2018-07-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install json-rpc2.0-node
pnpm add json-rpc2.0-node
yarn add json-rpc2.0-node
bun add json-rpc2.0-node
```

## 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 | 2.0.4 |
| Published | 2018-07-04 |
| First published | 2018-03-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 75.1 KB |
| Known vulnerabilities | 0 (+24 in 1 direct dependencies) |
| Install scripts | no |
| Author | i@xujif.com |
| Maintainers | xujif |
| Keywords | json-rpc, rpc, 2.0 |

## Links

- npm: https://www.npmjs.com/package/json-rpc2.0-node
- Homepage: https://github.com/xujif/ts-json-rpc
- npm.io page: https://npm.io/package/json-rpc2.0-node

## Dependencies (2)

- [axios](https://npm.io/package/axios.md) ^0.18.0
- [debug](https://npm.io/package/debug.md) ^3.1.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

- 2.0.4 (latest) — 2018-07-04
- 2.0.3 — 2018-06-29
- 2.0.2 — 2018-06-27
- 2.0.1 — 2018-06-27
- 2.0.0 — 2018-06-27
- 1.0.1 — 2018-06-27
- 1.0.0 — 2018-04-23
- 0.2.5 — 2018-03-15
- 0.2.4 — 2018-03-15
- 0.2.3 — 2018-03-15
- 0.2.2 — 2018-03-15
- 0.2.1 — 2018-03-15
- 0.2.0 — 2018-03-15
- 0.1.3 — 2018-03-14
- 0.1.2 — 2018-03-14
- … 4 more at https://npm.io/package/json-rpc2.0-node/versions

## README

### Client with http Trasport
```typescript
import { createHttpRpcClient } from 'json-rpc2.0-node'
const client = createHttpRpcClient('http://endpoint',{Authorization:"token or other headers, or other http header"})
const res = await client.invoke('method','param1','param2')
client.notify('method','param1','param2')

// or cast to an interface
const t:T = client.as<T>()
t.method('param1','param2')

```


### Client with custom Trasport
```typescript
// implement the transport interface
// export interface Transport {
//     (payload: string): Promise<string | undefined>
// }

import { Client,Trasport } from 'json-rpc2.0-node'

function Mytransport(json:string){
    return Promise.resolve(/*json respose*/)
}

const client = new Client(Mytransport)

```



### Server 
```typescript
import { Server } from 'json-rpc2.0-node'
const server = new Server()
server.expose('hello', () => 'hello world!')
const jsonbody = `
{
	"id":10,
	"method":"hello",
	"jsonrpc":"2.0"
}
`
const jsonrpcResponse = await server.handle(jsonbody)
// send your response back to client 

```

see more help in src/tests

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