import axios , { AxiosRequestConfig , AxiosResponse , CancelTokenSource } from "axios" ; import { stringify } from "querystring" ; import HttpStatus from './HttpStatus/HttpStatus' ; class HttpClient { public static instance : HttpClient = new HttpClient ( ) ; public mapList : Map < string , boolean > ; constructor ( ) { this . mapList = new Map ( ) ; } param url param http public httpClient ( url , http ) { http . interceptors . request . use ( ( config ) : any => { this . mapList . set ( "url" , false ) ; return config ; } ) ; http . interceptors . response . use ( ( config ) : any => { if ( ! this . mapList . get ( url ) ) { this . cancelToken ( ) ; this . mapList . delete ( url ) ; } const data = new HttpStatus ( config . data ) . init ( config . data ) ; return Promise . resolve ( data ) ; } , ( err ) => { return Promise . reject ( err ) ; } ) ; } param url param param1 public async init ( url , { ... params } , baseUrl = "http://localhost:3000/" ) { const axiosInit = axios . create ( { baseURL : baseUrl , method : "GET" , timeout : 10000 , ... params , data : stringify ( params . data ) , url , } ) ; await this . httpClient ( url , axiosInit ) ; return axiosInit ( url , { ... params } ) ; } public cancelToken ( ) { return axios . CancelToken . source ( ) ; } } export default HttpClient . instance ;