json-rpc3
TypeScript icon, indicating that this package has built-in type declarations

0.2.1 • Public • Published

JSON-RPC Typescript/Javascript wrapper

https://www.npmjs.com/package/json-rpc3 https://travis-ci.org/industral/json-rpc3 https://david-dm.org/industral/json-rpc3 https://david-dm.org/industral/json-rpc3?type=dev https://packagephobia.now.sh/result?p=json-rpc3 https://github.com/industral/json-rpc3/blob/master/LICENSE

Lightweight JSON-RPC Typescript/Javascript wrapper. Works with both browser and Node.js.

Example of use

Basic call
// In case running on Node.js, install and export globally `fetch`
import fetch from 'node-fetch';
global.fetch = fetch;
 
const json_rpc = new JSON_RPC({url: 'YOUR_URL'});
const results = await json_rpc.calls([{
  method: 'YOUR_METHOD',
  params: {}
}]);
 
const result = results.get();
Batch call, access by index
const results = await json_rpc.calls([{
  method: 'YOUR_METHOD_1',
  params: {}
}, {
  method: 'YOUR_METHOD_2',
  params: {}
}]);
 
const result1 = results.get(0); // access by index
const result2 = results.get(1);
Batch call, access by id
const id1 = new Date().valueOf();
const id2 = new Date().valueOf() + 1;
 
const results = await json_rpc.calls([{
  id: id1,
  method: 'YOUR_METHOD_1',
  params: {}
}, {
  id: id2,
  method: 'YOUR_METHOD_2',
  params: {}
}]);
 
const result2 = results.getById(id2);
const result1 = results.getById(id1);

Build (development)

npm ci
npm build:watch

Build (production)

Will produce esm, cjs and bundle modules.

npm run build

Test

npm run test

Package Sidebar

Install

npm i json-rpc3

Weekly Downloads

0

Version

0.2.1

License

MIT

Unpacked Size

19.7 kB

Total Files

28

Last publish

Collaborators

  • industral