mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios";
|
|
|
|
export class Api {
|
|
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);
|
|
}
|
|
} |