JSONRpc

an json-rpc 2.0 client lib for nodejs

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
22Nov 2, 2019Nov 3, 2016Minified + gzip package size for JSONRpc in KB

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()

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.