Merge pull request #8 from benhason1/feature--use-axios-function-signature
using axios function signature
This commit is contained in:
commit
1b0d806a69
1 changed files with 18 additions and 22 deletions
|
@ -1,34 +1,30 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { Inject } from '@nestjs/common';
|
import { Inject } from '@nestjs/common';
|
||||||
import Axios ,{AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
import Axios ,{ AxiosInstance } from 'axios';
|
||||||
import { AXIOS_INSTANCE_TOKEN } from "./http.constants";
|
import { AXIOS_INSTANCE_TOKEN } from "./http.constants";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class HttpService {
|
export class HttpService {
|
||||||
|
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(
|
constructor(
|
||||||
@Inject(AXIOS_INSTANCE_TOKEN)
|
@Inject(AXIOS_INSTANCE_TOKEN)
|
||||||
private readonly instance: AxiosInstance = Axios,
|
private readonly instance: AxiosInstance = Axios,
|
||||||
) {}
|
) {
|
||||||
request<T = any>(config: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
this.put = this.instance.put;
|
||||||
return this.instance.request(config)
|
this.post = this.instance.post;
|
||||||
}
|
this.patch = this.instance.patch;
|
||||||
get<T = any>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
this.head = this.instance.head;
|
||||||
return this.instance.get(url, config);
|
this.head = this.instance.head;
|
||||||
}
|
this.delete = this.instance.delete;
|
||||||
delete<T = any>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
this.get = this.instance.get;
|
||||||
return this.instance.delete(url, config);
|
this.request = this.instance.request;
|
||||||
}
|
|
||||||
head<T = any>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
|
||||||
return this.instance.head(url, config);
|
|
||||||
}
|
|
||||||
post<T = any>(url: string, data?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
|
||||||
return this.instance.post(url, data, config);
|
|
||||||
}
|
|
||||||
put<T = any>(url: string, data?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
|
||||||
return this.instance.put(url, data, config);
|
|
||||||
}
|
|
||||||
patch<T = any>(url: string, data?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
|
||||||
return this.instance.patch(url, data, config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get axiosRef(): AxiosInstance {
|
get axiosRef(): AxiosInstance {
|
||||||
|
|
Loading…
Reference in a new issue