import { Injectable } from '@nestjs/common'; import { Inject } from '@nestjs/common'; import Axios ,{AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'; import { AXIOS_INSTANCE_TOKEN } from "./http.constants"; @Injectable() export class HttpService { constructor( @Inject(AXIOS_INSTANCE_TOKEN) private readonly instance: AxiosInstance = Axios, ) {} request(config: AxiosRequestConfig): Promise> { return this.instance.request(config) } get(url: string, config?: AxiosRequestConfig): Promise> { return this.instance.get(url, config); } delete(url: string, config?: AxiosRequestConfig): Promise> { return this.instance.delete(url, config); } head(url: string, config?: AxiosRequestConfig): Promise> { return this.instance.head(url, config); } post(url: string, data?: Record, config?: AxiosRequestConfig): Promise> { return this.instance.post(url, data, config); } put(url: string, data?: Record, config?: AxiosRequestConfig): Promise> { return this.instance.put(url, data, config); } patch(url: string, data?: Record, config?: AxiosRequestConfig): Promise> { return this.instance.patch(url, data, config); } get axiosRef(): AxiosInstance { return this.instance } }