Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/miloas/jsonrpc
A simple json-rpc client for nodejs
https://github.com/miloas/jsonrpc
Last synced: 8 days ago
JSON representation
A simple json-rpc client for nodejs
- Host: GitHub
- URL: https://github.com/miloas/jsonrpc
- Owner: Miloas
- Created: 2016-11-03T20:12:56.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-04-03T08:25:26.000Z (over 1 year ago)
- Last Synced: 2024-09-23T09:06:30.073Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 17.6 KB
- Stars: 2
- Watchers: 3
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JSONRpc
> json-rpc 2.0 client
## Test
```javascript
// to Start an json-rpc 2.0 server
go run test/testServer.go
// do test
npm test
```## Install
```bash
npm i JSONRpc --save
```## Use
```javascript
var JSONRpcClient = require('JSONRpc')const client = new JSONRpcClient('localhost', 8080)
client.call('add', [1,7], (err, ret) => {
// 8
if(!err) console.log(ret)
})// Promise also support
(async () => {
let ret = await client.callPromise('add', [1,2])
// 3
console.log(ret)
})()//Json-rpc over websocket
//It will periodically call add function, and reseive every result from callback
client.callOverWs('add', [1, 2], function (err, ret) {
console.log(ret)
}, 1000)//It will call add once
client.callOverWs('add', [1, 2], function(err, ret) {
console.log(ret)
})//Close the connection
client.closeWs()
```