2021-09-07 18:25:31 +00:00
|
|
|
import { Injectable } from '@nestjs/common';
|
|
|
|
import { Inject } from '@nestjs/common';
|
2023-07-05 22:37:57 +00:00
|
|
|
import Axios, { AxiosInstance } from 'axios';
|
|
|
|
import { AXIOS_INSTANCE_TOKEN } from './http.constants';
|
2021-09-07 18:25:31 +00:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class HttpService {
|
2023-07-05 22:37:57 +00:00
|
|
|
public readonly put: typeof Axios.put;
|
|
|
|
public readonly post: typeof Axios.post;
|
|
|
|
public readonly patch: typeof Axios.patch;
|
|
|
|
public readonly head: typeof Axios.patch;
|
|
|
|
public readonly delete: typeof Axios.delete;
|
|
|
|
public readonly get: typeof Axios.get;
|
|
|
|
public readonly request: typeof Axios.request;
|
2021-12-23 17:20:41 +00:00
|
|
|
|
2023-07-05 22:37:57 +00:00
|
|
|
constructor(
|
|
|
|
@Inject(AXIOS_INSTANCE_TOKEN)
|
|
|
|
private readonly instance: AxiosInstance = Axios,
|
|
|
|
) {
|
|
|
|
this.put = this.instance.put;
|
|
|
|
this.post = this.instance.post;
|
|
|
|
this.patch = this.instance.patch;
|
|
|
|
this.head = this.instance.head;
|
|
|
|
this.head = this.instance.head;
|
|
|
|
this.delete = this.instance.delete;
|
|
|
|
this.get = this.instance.get;
|
|
|
|
this.request = this.instance.request;
|
|
|
|
}
|
2021-09-07 18:25:31 +00:00
|
|
|
|
2023-07-05 22:37:57 +00:00
|
|
|
get axiosRef(): AxiosInstance {
|
|
|
|
return this.instance;
|
|
|
|
}
|
2021-09-07 18:25:31 +00:00
|
|
|
}
|