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<boolean> {
    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<string> {
    const response = await axios.get(`${BASE}${this._url}/${PING}`);
    return response.data;
  }
}
