import axios from "axios"; import { HttpResponse } from "../response/HttpResponse"; export class HttpRequestFactory { public async getRequest(url: string): Promise { const response = await axios.get(url, { headers: { Accept: "application/json", "Content-Type": "application/json", }, }); if (response.status !== 200) { console.log(response); throw new Error(`Error status ${response.status} -- ${response.data}`); } else { return { status: response.status, response: response.data }; } } public async postRequest( url: string, data: any ): Promise { const response = await axios.post(url, data, { headers: { Accept: "application/json", "Content-Type": "application/json", }, }); if (response.status !== 200) { console.log(response); throw new Error(`Error status ${response.status} -- ${response.data}`); } else { return { status: response.status, response: response.data }; } } public async deleteRequest(url: string): Promise { const response = await axios.delete(url, { headers: { "Content-Type": "application/json", }, }); if (response.status !== 200) { console.log(response); throw new Error(`Error status ${response.status} -- ${response.data}`); } else { return { status: response.status, response: response.data }; } } }