Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dryajov/json-rpc-async
Simple transport agnostic JSON RPC module
https://github.com/dryajov/json-rpc-async
json-rpc remote-procedure-calls rpc
Last synced: 3 days ago
JSON representation
Simple transport agnostic JSON RPC module
- Host: GitHub
- URL: https://github.com/dryajov/json-rpc-async
- Owner: dryajov
- Created: 2019-02-19T05:51:15.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-22T03:28:00.000Z (almost 6 years ago)
- Last Synced: 2024-12-22T10:07:42.284Z (15 days ago)
- Topics: json-rpc, remote-procedure-calls, rpc
- Language: JavaScript
- Size: 43.9 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Async json rpc
> Simple transport agnostic JSON RPC module
## Why?
I wanted a simple transport agnostic RPC module that lets me use it with any duplex stream. I also wanted it to support basic class instance functionality, like inheritance, etc... This is it.
It uses JSON RPC as the rpc standard and by default sends all traffic as JSON, however, this can be serialized with something more efficient like messagepack or cbor as the network representation.
This module doesn't do any of that however, it leaves it to the user to decide which on the wire representation works better for its use case.
## Usage
> Client
```js
const stream = ... // get duplex streamconst methods = {
sayHello: () => {} // just a stub
}const rpc = createRpc({ stream, methods })
const hello = async () => {
const res = await rpc.sayHello()
console.log(res)
}hello() // prints 'Hello!'
```> Server
```js
const stream = ... // get duplex streamconst methods = {
sayHello: async () => { return 'Hello!' }
}createRpc({ stream, methods }) // listen for request
```Enjoy!
## Licence
MIT