JSPM

rpc-cli

1.2.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5
  • Score
    100M100P100Q33208F
  • License MIT

A rpc client base on JSON-RPC 2.0 Specification.

Package Exports

  • rpc-cli
  • rpc-cli/dist/index.browser.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (rpc-cli) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

rpc-cli

A rpc client base on JSON-RPC 2.0 Specification.

Installation

npm install -save rpc-cli

Examples

import Client, { Options } from 'rpc-cli';


const options: Options = {
  url: 'http://*.*.*:8001/rpc.endpoint',
  onError: (error) => {
    console.log(error);
  }
};

const client = new Client(options);
const result = await client.invoke('operation.sum', { a: 2, b: 3 });
console.log(result); 

Client

const client = new Client(options);
const result = await client.invoke('operation.sum', { a: 2, b: 3 });

new Client(options) -> client

Instantiate a rpc client

Options

{
  // url is the rpc server URL that will be used for the request.
  url: string,
  // version is the rpc server version, default is 2.0.
  version?: string,
  // http cookie. eg. your can pass sessionid.
  cookies?: string,
  // Fired when a request could not be processed due to an error. 
  // eg. server throw a error or network error.
  onError?: onErrorType,
  // Fired when a request is send.
  onRequest: onRequestType,
  // Fired when a request is end.
  onResponse: onResponseType,
}