Skip to content package
jsonrpc-lite v2.0.7 Parse and Serialize JSON-RPC2 messages in node.js or browser.
node any 0 deps cjs types open source
overview readme
license MIT
deps 0
unpacked 32.8 kB
files 6
node any $ npm install jsonrpc-lite@2.0.7n npmREADME GitHub-flavored package documentation.
downloads Across all versions.
Download trend unavailable.
compatibility Runtime metadata.
keywords Tagged topics.
json jsonrpc json-rpc jsonrpc2 serialize parse message
versions Latest published Sep 2, 2020
maintainers Registry package owners.
install size Estimated unpacked size across 1 packages.
99.5 kB
Includes dependencies.
Install npm install jsonrpc-lite copy
API const jsonrpc = require ( 'jsonrpc-lite' ) copy
jsonrpc.request(id, method[, params]) Creates a JSON-RPC 2.0 request object, return JsonRpc object.
id: {String|Integer}
method: {String}
params: {Object|Array}, optional
const requestObj = jsonrpc. request ( '123' , 'update' , {list: [ 1 , 2 , 3 ]})
// {
// jsonrpc: '2.0',
// id: '123',
// method: 'update',
// params: {list: [1, 2, 3]}
// } copy
jsonrpc.notification(method[, params]) Creates a JSON-RPC 2.0 notification object, return JsonRpc object.
method: {String}
params: {Object|Array}, optional
const notificationObj = jsonrpc. notification ( 'update' , {list: [ 1 , 2 , 3 ]})
// {
// jsonrpc: '2.0',
// method: 'update',
// params: {list: [1, 2, 3]}
// } copy
jsonrpc.success(id, result) Creates a JSON-RPC 2.0 success response object, return JsonRpc object.
id: {String|Integer}
result: {Mixed}
const successObj = jsonrpc. success ( '123' , 'OK' )
// {
// jsonrpc: '2.0',
// id: '123',
// result: 'OK',
// } copy
jsonrpc.error(id, error) Creates a JSON-RPC 2.0 error response object, return JsonRpc object.
id: {String|Integer}
error: {JsonRpcError}
const errorObj = jsonrpc. error ( '123' , new jsonrpc. JsonRpcError ( 'some error' , 99 ))
// {
// jsonrpc: '2.0',
// id: '123',
// error: {code: 99, 'message': 'some error'},
// } copy
jsonrpc.parse(message) Takes a JSON-RPC 2.0 payload (string) and tries to parse it into a JSON. If successful, determine what object is it (response, notification, success, error, or invalid), and return it's type and properly formatted object.
return an array, or an object of this format:
{
type : 'request' ,
payload : {
jsonrpc : '2.0' ,
id : 123 ,
method : 'update' ,
params : {}
}
} copy [{
type: 'request' ,
payload: {
jsonrpc: '2.0' ,
id: '123' ,
method: 'update' ,
params: [ 1 , 2 , 3 ]
}
}, {
type: 'notification' ,
payload: {
jsonrpc: '2.0' ,
method: 'update' ,
params: {_id: 'xxx' }
}
}, {
type: 'success' ,
payload: {
jsonrpc: '2.0' ,
id: '123' ,
result: 'OK'
}
}, {
type: 'error' ,
payload: {
jsonrpc: '2.0' ,
id: '123' ,
error: [jsonrpc.JsonRpcError object]
}
}, {
type: 'invalid' ,
payload: [jsonrpc.JsonRpcError object]
}] copy
jsonrpc.parseObject(message) Takes a JSON-RPC 2.0 payload (Object) and tries to parse it into a JSON. If successful, determine what object is it (response, notification, success, error, or invalid), and return it's type and properly formatted object.
return an JsonRpcParsed object with type and payload.
Class: jsonrpc.JsonRpc()
Class: jsonrpc.JsonRpcError(message, code[, data]) Create a JsonRpcError instance.
message: {String}
code: {Integer}
data: {Mixed} optional
const error = new jsonrpc. JsonRpcError ( 'some error' , 999 ) copy
Class Method: jsonrpc.JsonRpcError.invalidRequest([data])
Class Method: jsonrpc.JsonRpcError.methodNotFound([data])
Class Method: jsonrpc.JsonRpcError.invalidParams([data])
Class Method: jsonrpc.JsonRpcError.internalError([data])
Class Method: jsonrpc.JsonRpcError.parseError([data])