2020-03-12 11:57:57 -07:00
|
|
|
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios";
|
|
|
|
|
|
|
|
export class Api {
|
2020-03-13 09:02:54 -07:00
|
|
|
private api: AxiosInstance;
|
|
|
|
|
|
|
|
constructor (config: AxiosRequestConfig) {
|
|
|
|
this.api = axios.create(config);
|
|
|
|
this.api.interceptors.request.use((param: AxiosRequestConfig) => ({
|
|
|
|
...param
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected getUri (config?: AxiosRequestConfig): string {
|
|
|
|
return this.api.getUri(config);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected request<T, R = AxiosResponse<T>> (config: AxiosRequestConfig): Promise<R> {
|
|
|
|
return this.api.request(config);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected get<T, R = AxiosResponse<T>> (url: string, config?: AxiosRequestConfig): Promise<R> {
|
|
|
|
return this.api.get(url, config);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected delete<T, R = AxiosResponse<T>> (url: string, config?: AxiosRequestConfig): Promise<R> {
|
|
|
|
return this.api.delete(url, config);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected head<T, R = AxiosResponse<T>> (url: string, config?: AxiosRequestConfig): Promise<R> {
|
|
|
|
return this.api.head(url, config);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected post<T, R = AxiosResponse<T>> (url: string, data?: string, config?: AxiosRequestConfig): Promise<R> {
|
|
|
|
return this.api.post(url, data, config);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected put<T, R = AxiosResponse<T>> (url: string, data?: string, config?: AxiosRequestConfig): Promise<R> {
|
|
|
|
return this.api.put(url, data, config);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected patch<T, R = AxiosResponse<T>> (url: string, data?: string, config?: AxiosRequestConfig): Promise<R> {
|
|
|
|
return this.api.patch(url, data, config);
|
|
|
|
}
|
2020-03-12 11:57:57 -07:00
|
|
|
}
|