2.0.5 • Published 9 months ago
@piximind/api v2.0.5
Installation
Using npm
npm i -g npm
npm i @piximind/api
Usage
Method 1: API
const api = new Api()
constructor:
constructor(apiURL = 'http://localhost', port?: string)
interface:
interface ApiResponse {
status: Httpstatus;
data: any;
}
interface RefreshJson extends Partial<Response> {
accessToken: string;
refreshtoken: string;
}
interface IApi {
get(endPoint: string, headers: Headers, refrechCallback: () => Promise<Response>): Promise<ApiResponse>;
delete(endPoint: string, body: any, headers: Headers, refrechCallback: () => Promise<Response>): Promise<ApiResponse>;
post(endPoint: string, body: any, headers: Headers, refrechCallback: () => Promise<Response>): Promise<ApiResponse>;
put(endPoint: string, body: any, headers: Headers, refrechCallback: () => Promise<Response>): Promise<ApiResponse>;
patch(endPoint: string, body: any, headers: Headers, refrechCallback: () => Promise<Response>): Promise<ApiResponse>;
}
Method 2: CustomApi
const api = new CustomApi()
constructor:
constructor(params:ICustomApi)
interface:
export interface ICustomApi {
port: number
apiUrl: string
}
export interface ICallParams {
endPoint: string
method: Method
body?: any
headers: Headers
refrechCallback?: () => Promise<Response | string | boolean>
afterRefreshError?: () => Promise<any>
}
export interface ICustomApi {
port: number
apiUrl: string
}
export interface ICustomApiFunction {
createHeader(headerObject: HeaderObject): Headers;
call(params: ICallParams): Promise<ApiResponse>;
}