blue-frog-core
a small library for JSON-RPC 2.0.
api
var request = var response = var JsonRpcError =
create a json-rpc 2.0 request
var requestObject =
id
: string or number, case notification then null.method
: stringparams
: object or array. optional
var requestObject = // {// jsonrpc: '2.0',// method: 'sum',// id: 1,// params: [ 1, 3, 5 ]//}
create a json-rpc 2.0 request.notificacion
var notificationObj = request// or// var notificationObj = request(null, method[, params]) var requestObject = request// {// jsonrpc: '2.0',// method: 'update',// id: null,// params: [ 6 ]// }
create a json-rpc 2.0 response (success)
var responseObject =
id
: string or number or nullresult
: mix
var responseObject = // {// jsonrpc: '2.0',// id: 1,// result: 15// }
create a json-rpc 2.0 response (error)
var responseErrorObject = response
id
: string or number or nullerror
: object or errorObject
error member
code
: number -32768 to -32000message
: stringdata
: string or errorObject, optional.
use JsonRpcError
var responseErrorObject = response// {// jsonrpc: '2.0',// id: 1,// error: { [JsonRpcError: Server error]// name: 'JsonRpcError',// code: -32111,// message: 'Server error',// data: [Error: db error]// }// }var json = JSON// {// "jsonrpc": "2.0",// "id": 1,// "error": {// "code": -32111,// "message": "Server error",// "data": "Error: db error"// }// }
use object
var responseErrorObject = response// {// jsonrpc: '2.0',// id: 1,// error: {// code: -32112,// message: 'some error'// }// }var json = JSON// {// "jsonrpc": "2.0",// "id": 1,// "error": {// "code": -32112,// "message": "some error"// }// }
create json-rpc 2.0 error object
var err = code message data
create defined error object
var parseError = JsonRpcErrorvar invalidRequest = JsonRpcErrorvar methodNotFound = JsonRpcErrorvar invalidParams = JsonRpcErrorvar internalError = JsonRpcError
extensions
create a json-rpc 2.0 request/response/error extend object
var requestObject = requestvar responseObject = responsevar errorObject = responseerror var requestObject = request// {// jsonrpc: '2.0',// method: 'addMeta',// id: 3,// charset: 'utf8'// }
see also
license
MIT