async function fetchAPI
(
url: string,
method: 'GET' | 'POST' | 'PUT' | 'DELETE' = 'POST',
body?: TBody,
headers?: HeadersInit
): Promise {
const response = await fetch(url, {
method,
headers: {
'Content-Type': 'application/json',
...headers
},
body: JSON.stringify(body)
});
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json() as TResponse;
}
export default fetchAPI;