diff --git a/packages/backend/src/helpers/http-client/index.ts b/packages/backend/src/helpers/http-client/index.ts new file mode 100644 index 00000000..505ab46e --- /dev/null +++ b/packages/backend/src/helpers/http-client/index.ts @@ -0,0 +1,20 @@ +import axios, { AxiosInstance } from 'axios'; +import { IJSONObject, IHttpClientParams } from '@automatisch/types'; + +export default class HttpClient { + instance: AxiosInstance; + + constructor(params: IHttpClientParams) { + this.instance = axios.create({ + baseURL: params.baseURL, + }); + } + + async get(path: string, options?: IJSONObject) { + return await this.instance.get(path, options); + } + + async post(path: string, body: IJSONObject | string, options?: IJSONObject) { + return await this.instance.post(path, body, options); + } +} diff --git a/packages/types/index.d.ts b/packages/types/index.d.ts index c79e2ac2..574b53b9 100644 --- a/packages/types/index.d.ts +++ b/packages/types/index.d.ts @@ -175,3 +175,7 @@ export interface ISubstep { name: string; arguments: IField[]; } + +export type IHttpClientParams = { + baseURL: string; +}