// the base URL of the api; all requests start with it const base_url: string = "https://api.phite.ro"; /* export const makeGetRequest = async (path: string): Promise => { return await (await fetch( base_url + path )).json(); } */ // generic function that makes a web request const makeRequest = async (path: string, method: string, body?: string): Promise => { console.log( `making ${method} request: ${base_url + path}, ${body}` ); return fetch( base_url + path, { method: method, body: body ? body : null } ); } // the following functions are wrappers around `makeRequest`, // for every type of request that's needed. export const makeGetRequest = async (path: string): Promise => { return (await makeRequest( path, "GET" )).json(); } export const makePostRequest = async (path: string, body: T): Promise => { return (await makeRequest( path, "POST", JSON.stringify( body ) )).json(); } export const makePutRequest = async (path: string, body: T): Promise => { return (await makeRequest( path, "PUT", JSON.stringify( body ) )).json(); } export const makeDeleteRequest = async (path: string): Promise => { return (await makeRequest( path, "DELETE" )).json(); }