const API_BASE = ""; async function apiRequest(endpoint, options = {}) { const url = API_BASE + endpoint; const config = { headers: { "Content-Type": "application/json", }, credentials: "same-origin", ...options, }; if (options.body && typeof options.body === "object") { config.body = JSON.stringify(options.body); } const response = await fetch(url, config); const data = await response.json(); if (!response.ok) { throw new Error(data.message || "Request failed"); } return data; } async function get(endpoint) { return apiRequest(endpoint, { method: "GET" }); } async function post(endpoint, body) { return apiRequest(endpoint, { method: "POST", body }); } async function put(endpoint, body) { return apiRequest(endpoint, { method: "PUT", body }); } async function del(endpoint) { return apiRequest(endpoint, { method: "DELETE" }); } async function patch(endpoint, body) { return apiRequest(endpoint, { method: "PATCH", body }); }