import { Redirect } from "react-router-dom"; export interface HttpResponse extends Response { parsedBody?: T; } export async function http(request: RequestInfo): Promise> { const response: HttpResponse = await fetch(request); try { response.parsedBody = await response.json(); } catch (ex) {} if (!response.ok) { throw new Error(response.statusText); } return response; } export async function get( path: string, args: RequestInit = { method: "get" } ): Promise> { return await http(new Request(path, args)); } export async function post( path: string, body: any, args: RequestInit = { method: "post", body: JSON.stringify(body) } ): Promise> { return await http(new Request(path, args)); } export async function put( path: string, body: any, args: RequestInit = { method: "put", body: JSON.stringify(body) } ): Promise> { return await http(new Request(path, args)); }