JSONRpc
v0.3.20
Published
an json-rpc 2.0 client lib for nodejs
Downloads
124
Readme
JSONRpc
json-rpc 2.0 client
Test
// to Start an json-rpc 2.0 server
go run test/testServer.go
// do test
npm test
Install
npm i JSONRpc --save
Use
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()