export enum ApiMethods { GET = "GET", POST = "POST", } export enum ApiPaths { Login = "login", } type FetchApiProps = { method: ApiMethods; path: ApiPaths; body: T; }; type FetchApiResult = { error?: string; message?: string }; const fetchApi = async ({ method, path, body, }: FetchApiProps): Promise => { const response = await fetch(`/api/${path}`, { method: method, body: JSON.stringify(body), }); const { message } = await response.json(); if (response.ok) { return { message }; } else { return { error: message, }; } }; export default fetchApi;