Routers form working properly and listing
This commit is contained in:
+24
@@ -2,6 +2,9 @@ const API_BASE = import.meta.env.VITE_API_BASE;
|
||||
const API_KEY = import.meta.env.VITE_API_KEY;
|
||||
|
||||
export async function apiGet<T>(path: string): Promise<T> {
|
||||
console.log("API_BASE:", API_BASE);
|
||||
console.log("Calling:", `${API_BASE}${path}`);
|
||||
|
||||
const response = await fetch(`${API_BASE}${path}`, {
|
||||
headers: {
|
||||
"X-API-Key": API_KEY,
|
||||
@@ -12,5 +15,26 @@ export async function apiGet<T>(path: string): Promise<T> {
|
||||
throw new Error(`API error ${response.status}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
export async function apiPost<TResponse, TBody>(
|
||||
path: string,
|
||||
body: TBody
|
||||
): Promise<TResponse> {
|
||||
const response = await fetch(`${API_BASE}${path}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"X-API-Key": API_KEY,
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => null);
|
||||
throw new Error(error?.error || `API error ${response.status}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
Reference in New Issue
Block a user