1.0.7 • Published 3 years ago

js-json-rpc-client v1.0.7

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

js-json-rpc-client

Json rpc client

Installation

npm install js-json-rpc-client --save

Usage

TypeScript

import { Injectable } from "@angular/core";
import { RpcClient } from "js-json-rpc-client";
import { FetchTransport } from "js-json-rpc-client";

@Injectable({
  providedIn: "root"
})
export class RpcService {
  private token: string;
  private client: RpcClient;

  constructor() {
    this.client = new RpcClient(
      new FetchTransport({
        url: "http://127.0.0.1:8000/api",
        retryConfig: {
          maxRetryAttempts: 10,
          scalingDuration: 500
        }
      })
    );

    this.client.before(request => {
      if (this.token) {
        request.headers["Authorization"] = "Bearer " + this.token;
      }
    });
  }

  call(method: string, params?: { [key: string]: any }) {
    return this.client.call(method, params);
  }

  setToken(token: string) {
    this.token = token;
  }
}
1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.1

4 years ago

1.0.0

4 years ago