import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"; const headers: Readonly> = { Accept: "application/json", "Content-Type": "application/json; charset=utf-8", "Access-Control-Allow-Credentials": true, }; class HttpClient { private instance: AxiosInstance | null = null; private get http(): AxiosInstance { return this.instance != null ? this.instance : this.initHttp(); } get>( url: string, config?: AxiosRequestConfig, ): Promise { return this.http.get(url, config); } post>( url: string, data?: T, config?: AxiosRequestConfig, ): Promise { return this.http.post(url, data, config); } put>( url: string, data?: T, config?: AxiosRequestConfig, ): Promise { return this.http.put(url, data, config); } patch>( url: string, data?: T, config?: AxiosRequestConfig, ): Promise { return this.http.patch(url, data, config); } delete>( url: string, config?: AxiosRequestConfig, ): Promise { return this.http.delete(url, config); } private initHttp() { const http = axios.create({ baseURL: "https://soroban-dapps-challenge-wrangler.julian-martinez.workers.dev", headers, }); this.instance = http; return http; } } export const httpClient = new HttpClient();