https://github.com/industral/json-rpc3
Javascript JSON-RPC wrapper
https://github.com/industral/json-rpc3
javascript json-rpc json-rpc-client json-rpc2 json-rpc2-client typescript
Last synced: 7 months ago
JSON representation
Javascript JSON-RPC wrapper
- Host: GitHub
- URL: https://github.com/industral/json-rpc3
- Owner: industral
- License: mit
- Created: 2019-06-05T19:07:02.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T06:07:20.000Z (about 3 years ago)
- Last Synced: 2025-06-21T06:35:55.497Z (7 months ago)
- Topics: javascript, json-rpc, json-rpc-client, json-rpc2, json-rpc2-client, typescript
- Language: JavaScript
- Size: 1.22 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# JSON-RPC Typescript/Javascript wrapper






Lightweight JSON-RPC Typescript/Javascript wrapper.
Works with both browser and Node.js.
### Example of use
##### Basic call
```javascript
// 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
```javascript
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
```javascript
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)
```bash
npm ci
npm build:watch
```
### Build (production)
Will produce `esm`, `cjs` and `bundle` modules.
```bash
npm run build
```
### Test
```bash
npm run test
```