Simple yet powerful JSON-RPC client for JavaScript and Node.js. If you need a server, try sepc.
npm i repcrepc(url, options)Call:
import repc from 'repc';
const math = repc('https://math.juana.dev/v1');
const result = await math.call('add', [2, 2]);Notification:
import repc from 'repc';
const math = repc('https://math.juana.dev/v1');
math.notify('ping');Batch:
import repc from 'repc';
const math = repc('https://math.juana.dev/v1');
const responses = await math.batch(
(builder) => builder
.call('add', [2, 2])
.call('div', [3.14, 0])
.call('mul', [6, 6])
.call('sub', [10, 5])
.notify('ping')
);Request ID generation function.
- type:
function(method, params)
Data transporter. Must implement transport function which returns Promise<string>.
- type:
object - example:
const httpTransporter = {
transport: (url, data, context) =>
fetch(url, {
body: JSON.stringify(data),
headers: context.options.headers,
}).then((r) => r.text()),
}Make request. Returns response.
Call method. Returns result.
Send notification. Returns nothing.
Make several requests at the same time. Returns array of responses.