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

34 lines
1.1 KiB
TypeScript
Raw Normal View History

import { Injectable } from '@nestjs/common';
import { Inject } from '@nestjs/common';
2021-12-23 17:20:41 +00:00
import Axios ,{ AxiosInstance } from 'axios';
import { AXIOS_INSTANCE_TOKEN } from "./http.constants";
@Injectable()
export class HttpService {
2021-12-23 17:20:41 +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;
constructor(
@Inject(AXIOS_INSTANCE_TOKEN)
private readonly instance: AxiosInstance = Axios,
2021-12-23 17:20:41 +00:00
) {
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;
}
get axiosRef(): AxiosInstance {
return this.instance
}
}