// Auto-generated API client for NoteApp const API_BASE = process.env.NEXT_PUBLIC_API_URL || "http://localhost:3001/api"; interface RequestOptions extends RequestInit { params?: Record; } async function request(endpoint: string, options: RequestOptions = {}): Promise { const { params, ...init } = options; let url = `${API_BASE}${endpoint}`; if (params) { const searchParams = new URLSearchParams(); Object.entries(params).forEach(([k, v]) => searchParams.set(k, String(v))); url += `?${searchParams.toString()}`; } const res = await fetch(url, { ...init, headers: { "Content-Type": "application/json", ...init.headers, }, }); if (!res.ok) { const err = await res.json().catch(() => ({ message: res.statusText })); throw new Error(err.message || `API Error: ${res.status}`); } return res.json(); } export const api = { get: (url: string, params?: Record) => request(url, { method: "GET", params }), post: (url: string, data?: unknown) => request(url, { method: "POST", body: JSON.stringify(data) }), put: (url: string, data?: unknown) => request(url, { method: "PUT", body: JSON.stringify(data) }), delete: (url: string) => request(url, { method: "DELETE" }), };