UNPKG

trident-beta

Version:

trident is a sample and lightly tools aims to improve collaboration efficiency between SDET and QA based on initiative from Einstein/TestIT.

91 lines (81 loc) 1.88 kB
import axios, { AxiosRequestConfig, AxiosResponse } from "axios"; axios.defaults.withCredentials = true; class HttpClient { public async get( url: string, config: AxiosRequestConfig ): Promise<AxiosResponse> { const requestConfig: AxiosRequestConfig = { url, method: "get", ...config }; return this._sendRequest(requestConfig); } public async post( url: string, config: AxiosRequestConfig ): Promise<AxiosResponse> { const requestConfig: AxiosRequestConfig = { url, method: "post", ...config }; return this._sendRequest(requestConfig); } public async put( url: string, config: AxiosRequestConfig ): Promise<AxiosResponse> { const requestConfig: AxiosRequestConfig = { url, method: "put", ...config }; return this._sendRequest(requestConfig); } public async patch( url: string, config: AxiosRequestConfig ): Promise<AxiosResponse> { const requestConfig: AxiosRequestConfig = { url, method: "patch", ...config }; return this._sendRequest(requestConfig); } public async delete( url: string, config: AxiosRequestConfig ): Promise<AxiosResponse> { const requestConfig: AxiosRequestConfig = { url, method: "delete", ...config }; return this._sendRequest(requestConfig); } public async head( url: string, config: AxiosRequestConfig ): Promise<AxiosResponse> { const requestConfig: AxiosRequestConfig = { url, method: "head", ...config }; return this._sendRequest(requestConfig); } private async _sendRequest( config: AxiosRequestConfig ): Promise<AxiosResponse> { try { return await axios(config); } catch (err) { console.error(err); throw err; } } } export default HttpClient;