39246-vm/frontend/lib/api/config.ts
abbashkyt-creator 7d8ce0e322 V0.1
2026-03-14 04:02:22 +03:00

19 lines
694 B
TypeScript

const BASE = 'http://localhost:8000'
// GET /api/config returns a flat dict {key: value} — return it directly.
export const fetchConfig = async (): Promise<Record<string, string>> => {
const res = await fetch(`${BASE}/api/config`)
if (!res.ok) throw new Error('Failed to fetch config')
return res.json()
}
// POST /api/config expects a flat dict {key: value} — send data directly.
export const saveConfig = async (data: Record<string, string>): Promise<void> => {
const res = await fetch(`${BASE}/api/config`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
})
if (!res.ok) throw new Error('Failed to save config')
}