json-rpc-response
v1.0.3
Published
JSON RPC 2.0 response object constructor.
Downloads
9
Readme
JSON RPC 2.0 Response
Constructor for JSON RPC 2.0 response objects.
Also see related packages json-rpc-request, json-rpc-notification, and json-rpc-error
Installation
npm install json-rpc-response
Usage
new JsonRpcResponse(id, error, result);
Response objects can be constructed with or without using the new
keyword.
Arguments error
and result
are mutually exclusive. Argument result
must be
undefined if passing error
. Pass null
as error if result
exists.
Example
var JsonRpcResponse = require('json-rpc-response');
// Result response
new JsonRpcResponse(1, null, 'some result');
// Error response
new JsonRpcResponse(1, { code: -1, message: 'some error' });
Test
Run unit tests;
$ npm test