HR / HR_System /src /services /apiClient.js
Vipooshanb's picture
Create backend fastapi
af841c4
Raw
History Blame Contribute Delete
655 Bytes
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || '/api'
function buildUrl(path) {
const normalizedPath = path.startsWith('/') ? path : `/${path}`
return `${API_BASE_URL}${normalizedPath}`
}
export async function request(path, options = {}) {
const response = await fetch(buildUrl(path), {
headers: {
'Content-Type': 'application/json',
...(options.headers || {}),
},
...options,
})
if (!response.ok) {
const details = await response.text()
throw new Error(details || `Request failed with status ${response.status}`)
}
if (response.status === 204) {
return null
}
return response.json()
}