BREATHE / frontend /src /api /client.js
tannuiscoding's picture
Remove Hugging Face Spaces base prefix for API routes
abd0b64
raw
history blame contribute delete
742 Bytes
const BASE = ''
async function request(path, options = {}) {
const url = path.startsWith('/') ? `${BASE}${path}` : `${BASE}/${path}`
const res = await fetch(url, {
credentials: 'include',
headers: { 'Content-Type': 'application/json', ...(options.headers || {}) },
...options,
})
const json = await res.json().catch(() => ({}))
if (!res.ok) throw new Error(json.error || `HTTP ${res.status}`)
return json
}
export const api = {
get: (path) => request(path),
post: (path, body) => request(path, { method: 'POST', body: JSON.stringify(body) }),
put: (path, body) => request(path, { method: 'PUT', body: JSON.stringify(body) }),
del: (path) => request(path, { method: 'DELETE' }),
}