@sarpere/uxios
v2.0.5
Published
Udentify Axios Module
Downloads
2
Readme
Uxios
Promise based HTTP client for the browser and node.js. It Allows to use http request more clear, readable and fast.
Installing
Using npm:
$ npm install --registry {verdaccioUrl} uxios
Using yarn:
$ yarn add --registry {verdaccioUrl} uxios
Usage
To initialize model
import Uxios from "Uxios";
class apiModel extends Uxios {
constructor(){
super({ axiosConfig: { "api-url" , "refresh-token-url" } })
}
}
Javascript Usage
class CameraService extends apiModel {
constructor() {
super();
this.Prefix('Cameras');
}
/**
* @description Get Camera
* @param Id
* @returns Camera
*/
Camera(Id) {
return this.PrefixId(Id).Get().Save();
}
}
Typescript Usage
class CameraService extends apiModel {
constructor() {
super();
this.Prefix('Cameras');
}
/**
* @description Get Camera
* @param {CameraTypes.CameraId} Id
* @returns Camera
*/
Camera(Id: CameraTypes.CameraId) {
return this.PrefixId(Id).Get().Save<CameraTypes.Camera>();
}
}
Typescript Refresh Token Usage
// resolveToken is required!
const resolveToken = (loginResponse: ApiResponse<{ access_token: string }>) => {
return loginResponse.Data.access_token;
};
class udfModel extends Uxios {
constructor() {
super({ axiosConfig: { baseURL: 'apiurl', refreshTokenUrl: '/Token', resolveToken } });
}
}