1.0.12 • Published 3 years ago

repc v1.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

repc

Simple yet powerful JSON-RPC client for JavaScript and Node.js. If you need a server, try sepc.

Installation

npm i repc

Usage

repc(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')
);

Options

id

Request ID generation function.

  • type: function(method, params)

transporter

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()),
}

Methods

send(request, options)

Make request. Returns response.

call(method, params, options)

Call method. Returns result.

notify(method, params, options)

Send notification. Returns nothing.

batch(builder, options)

Make several requests at the same time. Returns array of responses.

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.0.1

3 years ago