import axios from "axios"; import * as https from "https"; export class RestAPI { private _method: string = "POST"; private _apiURL: string = "/"; private _payload: object = {}; httpsAgent() { return new https.Agent({ rejectUnauthorized: false, }); } async get(_apiURL: string) { try { const response = await axios.get(_apiURL); return response; } catch (error) { console.log(error); } } async post() { try { const resp = await axios.post(this._apiURL, this._payload, { httpsAgent: this.httpsAgent(), }); return resp; } catch (error) { console.log(error); } } async put(_apiURL: string) { try { const resp = await axios.put(this._apiURL, this._payload, { httpsAgent: this.httpsAgent(), }); return resp; } catch (error) { console.log(error); } } executeCall(_method: string, _apiURL: string, _payload?: object) { this._apiURL = _apiURL; this._method = _method; this._payload = _payload || {}; switch (this._method) { case "GET": return this.get(this._apiURL); case "POST": return this.post(); case "PUT": return this.put(this._apiURL); case "DELETE": return this.put(this._apiURL); } } }