%PDF- %PDF-
| Direktori : /home2/rezakur1/public_html/portfolio/portfolio-rezakurnia/src/lib/api/ |
| Current File : //home2/rezakur1/public_html/portfolio/portfolio-rezakurnia/src/lib/api/client.ts |
const BASE_URL =
import.meta.env.PUBLIC_API_URL ||
"https://api.rezakurnia.com";
type ApiResponse<T> = {
status: string;
data: T;
message?: string;
};
export async function apiGet<T>(endpoint: string): Promise<ApiResponse<T>> {
try {
const res = await fetch(`${BASE_URL}${endpoint}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
if (!res.ok) {
throw new Error(`API Error: ${res.status}`);
}
return await res.json();
} catch (error) {
console.error("API GET ERROR:", error);
throw error;
}
}