diff --git a/web-app/src/Services/HttpClient.ts b/web-app/src/Services/HttpClient.ts new file mode 100644 index 0000000..039ae40 --- /dev/null +++ b/web-app/src/Services/HttpClient.ts @@ -0,0 +1,31 @@ +import axios from "axios"; + +const BASE = "https://"; +const PING = "ping"; +const RACLETTE = "raclette"; +const PONG = "pong"; + +export class HttpClient { + private _url: string; + + constructor(url: string) { + this._url = url; + } + + async isConnected(): Promise { + var connected = false; + if (await this.ping()) { + connected = true; + console.log("Connected to backend!"); + } else { + connected = false; + console.log("Connection failed backend!"); + } + return connected; + } + + private async ping(): Promise { + const response = await axios.get(`${BASE}${this._url}/${PING}`); + return response.data; + } +}