14 lines
472 B
TypeScript
14 lines
472 B
TypeScript
const API = process.env.NEXT_PUBLIC_API_URL || "http://localhost:18888";
|
|
|
|
export async function fetchAPI<T>(path: string): Promise<T> {
|
|
const res = await fetch(`${API}${path}`);
|
|
if (!res.ok) throw new Error(`API error: ${res.status}`);
|
|
return res.json();
|
|
}
|
|
|
|
export async function postAPI<T>(path: string): Promise<T> {
|
|
const res = await fetch(`${API}${path}`, { method: "POST" });
|
|
if (!res.ok) throw new Error(`API error: ${res.status}`);
|
|
return res.json();
|
|
}
|