import axios , { AxiosPromise , AxiosInterceptorManager , AxiosRequestConfig , } from 'axios' ; import { from , Observable } from 'rxjs' ; import { Injectable } from '@indiv/di' ; export interface HttpClientRequestConfig extends AxiosRequestConfig { } export interface HttpClientResponse < T = any > { data : T ; status : number ; statusText : string ; headers : any ; config : HttpClientRequestConfig ; request ? : any ; } export interface HttpClientRequestInstance { ( config ) : AxiosPromise ; ( url , config ? ) : AxiosPromise ; defaults : HttpClientRequestConfig ; interceptors : { request : AxiosInterceptorManager < HttpClientRequestConfig > ; response : AxiosInterceptorManager < HttpClientResponse > ; } ; request < T = any > ( config ) : AxiosPromise < T > ; get < T = any > ( url , config ? ) : AxiosPromise < T > ; delete ( url , config ? ) : AxiosPromise ; head ( url , config ? ) : AxiosPromise ; post < T = any > ( url , data ? , config ? ) : AxiosPromise < T > ; put < T = any > ( url , data ? , config ? ) : AxiosPromise < T > ; patch < T = any > ( url , data ? , config ? ) : AxiosPromise < T > ; } export class @ Injectable ( { providedIn : 'root' , } ) export class HttpClient { param { string } url param { HttpClientRequestConfig } config returns { HttpClientRequestInstance } memberof public createRequest ( url , config ) { const newConfig = Object . assign ( { url } , config ) ; return axios . create ( newConfig ) ; } template T param { HttpClientRequestConfig } config returns { Observable < HttpClientResponse < T > > } memberof public request < T = any > ( url , config ) { const newConfig = Object . assign ( { url } , config ) ; return from ( axios . request ( newConfig ) ) ; } template T param { string } url param { HttpClientRequestConfig } config returns { Observable < HttpClientResponse < T > > } memberof public get < T = any > ( url , config ? ) { return from ( axios . get ( url , config ) ) ; } param { string } url param { HttpClientRequestConfig } config returns { Observable < HttpClientResponse < any > > } memberof public delete ( url , config ? ) { return from ( axios . delete ( url , config ) ) ; } param { string } url param { HttpClientRequestConfig } config returns { Observable < HttpClientResponse < any > > } memberof public head ( url , config ? ) { return from ( axios . head ( url , config ) ) ; } template T param { string } url param { HttpClientRequestConfig } config returns { Observable < HttpClientResponse < T > > } memberof public post < T = any > ( url , config ? ) { return from ( axios . post ( url , config ) ) ; } template T param { string } url param { HttpClientRequestConfig } config returns { Observable < HttpClientResponse < T > > } memberof public put < T = any > ( url , config ? ) { return from ( axios . put ( url , config ) ) ; } template T param { string } url param { HttpClientRequestConfig } config returns { Observable < HttpClientResponse < T > > } memberof public patch < T = any > ( url , config ? ) { return from ( axios . patch ( url , config ) ) ; } param { ( ( value : HttpClientRequestConfig ) => HttpClientRequestConfig | Promise < HttpClientRequestConfig > ) } onFulfilled param { ( error : any ) => any } onRejected returns { number } memberof public createRequestInterceptor ( onFulfilled ? , onRejected ? ) { return axios . interceptors . request . use ( onFulfilled , onRejected ) ; } param { number } requestInterceptor memberof public removeRequestInterceptor ( requestInterceptor ) { axios . interceptors . request . eject ( requestInterceptor ) ; } param { ( ( value : HttpClientResponse ) => HttpClientResponse | Promise < HttpClientResponse > ) } onFulfilled param { ( error : any ) => any } onRejected returns { number } memberof public createResponseInterceptor ( onFulfilled ? , onRejected ? ) { return axios . interceptors . response . use ( onFulfilled , onRejected ) ; } param { number } responseInterceptor memberof public removeResponseInterceptor ( responseInterceptor ) { axios . interceptors . response . eject ( responseInterceptor ) ; } }