1.0.0 • Published 6 years ago

js-jsonrpc-request v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

Isomorphic JSON-RPC 2.0 client for browser and Node.js with logging curl and time.

Installation

yarn add js-jsonrpc-request

or

npm install js-jsonrpc-request --save

Usage

import JsonRpcClient from 'js-jsonrpc-request';

const jsonrpc = new JsonRpcClient({
    apiRoute: '/api/rpc/v1.0',
    headers: {
        'X-API-CLIENT': 'key',
    },
    withMeta: true,
});

jsonrpc
    .request('info.getSomething', { data: 'something' })
    .then(({ data, meta }) => {
        console.log('Data', data);
        console.log('Curl', meta.curl);
        console.log('Time for request', `${meta.timeRequest} ms`);
    })
    .catch((err) => console.log('ERROR', err));

data - data response from API

curl - curl for request API, for example

curl -i -X POST -H 'Content-Type: application/json' -H 'X-API-CLIENT: key' --data-binary '{"jsonrpc":"2.0","method":"info.getSomething","params":{"data":"something"},"id":1}' 'http://example.com/api/rpc/v1.0'

timeRequest - time in ms for request (for example 305 ms)

1.0.0

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago