Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fullpipe/js-json-rpc-client
https://github.com/fullpipe/js-json-rpc-client
Last synced: about 4 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/fullpipe/js-json-rpc-client
- Owner: fullpipe
- License: mit
- Created: 2020-01-20T18:55:46.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-04-28T22:17:42.000Z (over 2 years ago)
- Last Synced: 2024-10-13T03:20:04.826Z (about 1 month ago)
- Language: TypeScript
- Size: 56.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# js-json-rpc-client
Json rpc client
## Installation
```sh
npm install js-json-rpc-client --save
```## Usage
### TypeScript
```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;
}
}
```