Client
A fetch wrapper + a progress-tracked
file upload, both injecting the active profile header and parsing the
server's structured error envelope.
Variables¶
API_BASE¶
Defined in: src/shared/api/client.ts:10
Single source of truth for the API base (dev server proxies /api).
Functions¶
apiFetch()¶
Defined in: src/shared/api/client.ts:54
A fetch replacement that prefixes the API base for relative URLs, injects
the X-Profile-ID header, throws ApiError on non-2xx, and parses the
response by content-type.
Type Parameters¶
| Type Parameter | Default type | Description |
|---|---|---|
T |
unknown |
Parameters¶
| Parameter | Type | Description |
|---|---|---|
url |
string |
Relative API path (or absolute URL). |
opts? |
RequestInit |
Fetch options. |
Returns¶
Promise\<T>
The parsed response.
uploadFile()¶
Defined in: src/shared/api/client.ts:154
Uploads a file via a streaming XMLHttpRequest with progress, mirroring
apiFetch (profile header, ApiError, JSON response).
Type Parameters¶
| Type Parameter | Default type | Description |
|---|---|---|
T |
unknown |
The expected JSON response type. |
Parameters¶
| Parameter | Type | Description |
|---|---|---|
file |
File |
The file to upload. |
url |
string |
The API endpoint. |
headers |
Record\<string, string> |
Additional request headers. |
onProgress |
(percent) => void |
Upload progress callback. |
onUploadComplete |
() => void |
Called when the upload hits 100%. |
Returns¶
Promise\<T>
The parsed JSON response.
uploadFormData()¶
Defined in: src/shared/api/client.ts:200
Uploads multipart/form-data via a progress-tracked XMLHttpRequest,
mirroring uploadFile (profile header, ApiError, JSON
response). The file rides in the form body, so large structured metadata is
a form field rather than a size-limited header. The browser sets the
multipart Content-Type (with boundary), so it is deliberately not set here.
Type Parameters¶
| Type Parameter | Default type | Description |
|---|---|---|
T |
unknown |
The expected JSON response type. |
Parameters¶
| Parameter | Type | Description |
|---|---|---|
url |
string |
The API endpoint. |
formData |
FormData |
The multipart payload (file part + fields). |
onProgress |
(percent) => void |
Upload progress callback. |
onUploadComplete |
() => void |
Called when the upload hits 100%. |
Returns¶
Promise\<T>
The parsed JSON response.