nestjs-http-promise/lib/http.service.ts

33 lines
1,004 B
TypeScript
Raw Normal View History

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';
@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 as typeof Axios.patch;
2023-07-05 22:37:57 +00:00
this.delete = this.instance.delete;
this.get = this.instance.get;
this.request = this.instance.request;
}
2023-07-05 22:37:57 +00:00
get axiosRef(): AxiosInstance {
return this.instance;
}
}