Kelvin SDK Client for modern frontend Javascript frameworks, like Vue or React
npm install @kelvininc/web-client-sdkKelvin SDK Client provides a simple way to integrate our Authentication, Services and Models inside your project.
To run our SDK inside your project you need to support the following versions:
- Rxjs: ~6.6.X
- Axios: >=1.0.0
- Optionally, keycloak-js to handle the authentication
Install the Kelvin SDK Client, RxJS and Axios Client:
``bash`
npm install @kelvininc/web-client-sdk axios rxjs@~6.6.7 --save
`js
import KelvinSDK from "@kelvininc/web-client-sdk";
import axios from "axios";
const configuration = {
baseUrl: '
authConfig: {
clientId: '
realm: '
url: '
}
}
KelvinSDK.initialize(configuration, axios);
`
The Kelvin SDK Client is now ready to use.
If you need to initialize our SDK services, this example can run inside your Application:
You can import service and modules from Kelvin Core.
`js`
import { AuthService, ACPService } from "@kelvininc/web-client-sdk";
js
AuthService.login({
username: '',
password: ''
}).subscribe(({ accessToken, refreshToken }) => doSomething());
`$3
`js
ACPService.listACP({
pageSize: 20
}).subscribe(acpList => doSomething(acpList));
`#### Promise transformation (if you prefer)
`js
ACPService.listACP({ pageSize: 20 }).toPromise()
.then(acpList => doSomething(acpList));
`---
Abort Requests
This library uses axios as HTTP Client to communicate with the server-side. Since we encapsulate the request into an observable, we have two options to abort a request:
1. Unsubscribe from the
Subscription`js
const sub = ACPService.listACP({ pageSize: 20 })
.subscribe(acpList => doSomething(acpList));sub.unsubcribe();
`2. Abort the request using
KvRequestAbortController. To use this approach it's necessary to declare the class and pass it through the request options as requestController. After the request is built in the SDK we can access the cancel option from the class.`js
const requestController = new KvRequestAbortController();await ACPService.listACP(
{ pageSize: 20 },
{ requestController } as IKvWebHttpRequestOptions
)
.toPromise()
.then(acpList => doSomething(acpList));
// To cancel the request
requestController.cancel();
``---
You can find the full Client API reference here.