Skip to content

Api

This file contains the apiFetch function, which is a wrapper around the native fetch function.

Functions

apiFetch()

function apiFetch<T>(url, opts?): Promise<T>;

Defined in: src/services/api.ts:21

A fetch replacement that:

  • Auto-prefixes BASE for relative URLs
  • Adds X-Profile-ID header if a profile is set in localStorage
  • Throws ApiError on non-2xx
  • Parses JSON/text/blob based on content-type

Type Parameters

Type Parameter Default type Description
T unknown

Parameters

Parameter Type Description
url string The URL to fetch.
opts? RequestInit The options for the fetch request.

Returns

Promise\<T>

A promise that resolves to the response data.


uploadFile()

function uploadFile<T>(
  file,
  url,
  headers,
  onProgress,
  onUploadComplete,
): Promise<T>;

Defined in: src/services/api.ts:71

Uploads a file to the server using a streaming request with progress tracking. It mirrors the behavior of apiFetch by automatically adding the profile ID, handling errors with ApiError, and providing a consistent API.

Type Parameters

Type Parameter Default type Description
T unknown The expected type of the JSON response.

Parameters

Parameter Type Description
file File The file to upload.
url string The API endpoint to upload the file to.
headers { [key: string]: string; } A dictionary of additional headers to send with the request.
onProgress (percent) => void A callback function that receives the upload progress as a percentage.
onUploadComplete () => void A callback function that is triggered when the upload portion is 100% complete.

Returns

Promise\<T>

A promise that resolves with the JSON response from the server.