Created
February 24, 2022 08:19
-
-
Save muhammadfaizan/e219ae4bc415b0f761f9e5bd718658cf to your computer and use it in GitHub Desktop.
Base Class Client Respository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios' | |
export class ResourcesRestClient { | |
private instance: AxiosInstance | |
private config?: AxiosRequestConfig | |
constructor(client: AxiosInstance, config?: AxiosRequestConfig) { | |
this.instance = client | |
this.config = config | |
} | |
public post<RequestType>(url: string) { | |
return (req: RequestType, config?: AxiosRequestConfig): Promise<AxiosResponse<ResponseType>> => | |
this.instance.post<RequestType, AxiosResponse<ResponseType>>(url, req, config) | |
} | |
public get<RequestType>(url: string) { | |
return (req: RequestType, config?: AxiosRequestConfig): Promise<AxiosResponse<ResponseType>> => | |
this.instance.get<RequestType, AxiosResponse<ResponseType>>(url, config || this.config) | |
} | |
public delete<RequestType, ResponseType>(url: string) { | |
return (req: RequestType, config?: AxiosRequestConfig): Promise<AxiosResponse<ResponseType>> => | |
this.instance.post<RequestType, AxiosResponse<ResponseType>>(url, req, config) | |
} | |
public patch<RequestType, ResponseType>(url: string) { | |
return (req: RequestType, config?: AxiosRequestConfig): Promise<AxiosResponse<ResponseType>> => | |
this.instance.post<RequestType, AxiosResponse<ResponseType>>(url, req, config) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment