From 16e299a12d27585819a74a72c96811134fa558c7 Mon Sep 17 00:00:00 2001 From: Faruk AYDIN Date: Fri, 15 Jul 2022 19:56:48 +0300 Subject: [PATCH] feat: Implement basic http client --- .../backend/src/helpers/http-client/index.ts | 20 +++++++++++++++++++ packages/types/index.d.ts | 4 ++++ 2 files changed, 24 insertions(+) create mode 100644 packages/backend/src/helpers/http-client/index.ts 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; +}