ApiClient
Core API Client for handling HTTP requests to the WebbiOS API.
This class wraps the native fetch API, injects authentication headers,
and handles global 401 Unauthorized responses.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ApiClient(
options?):ApiClient
Initializes a new ApiClient instance.
Parameters
Section titled “Parameters”options?
Section titled “options?”WebbiSDKOptions = {}
Initialization configuration.
Returns
Section titled “Returns”ApiClient
Methods
Section titled “Methods”delete()
Section titled “delete()”delete(
path,options?):Promise<any>
Performs an HTTP DELETE request.
Parameters
Section titled “Parameters”string
The relative API path.
options?
Section titled “options?”RequestInit
Additional Fetch options.
Returns
Section titled “Returns”Promise<any>
The parsed JSON response.
fetch()
Section titled “fetch()”fetch(
path,options?):Promise<any>
Performs a raw HTTP request to the configured API endpoint.
Parameters
Section titled “Parameters”string
The relative API path (e.g., /auth/me).
options?
Section titled “options?”RequestInit = {}
Standard Fetch API RequestInit options.
Returns
Section titled “Returns”Promise<any>
A promise resolving to the parsed JSON response.
Throws
Section titled “Throws”Will throw an Error if the response status is not OK (2xx).
get(
path,options?):Promise<any>
Performs an HTTP GET request.
Parameters
Section titled “Parameters”string
The relative API path.
options?
Section titled “options?”RequestInit
Additional Fetch options.
Returns
Section titled “Returns”Promise<any>
The parsed JSON response.
post()
Section titled “post()”post(
path,body,options?):Promise<any>
Performs an HTTP POST request.
Parameters
Section titled “Parameters”string
The relative API path.
any
The request payload (will be stringified as JSON).
options?
Section titled “options?”RequestInit
Additional Fetch options.
Returns
Section titled “Returns”Promise<any>
The parsed JSON response.
put(
path,body,options?):Promise<any>
Performs an HTTP PUT request.
Parameters
Section titled “Parameters”string
The relative API path.
any
The request payload (will be stringified as JSON).
options?
Section titled “options?”RequestInit
Additional Fetch options.
Returns
Section titled “Returns”Promise<any>
The parsed JSON response.
setRefreshCallback()
Section titled “setRefreshCallback()”setRefreshCallback(
cb):void
Registers a callback that will be triggered when an API request fails with a 401 Unauthorized status code.
Parameters
Section titled “Parameters”() => void
The callback function.
Returns
Section titled “Returns”void
setToken()
Section titled “setToken()”setToken(
token):void
Sets or updates the JWT access token for subsequent requests.
Parameters
Section titled “Parameters”string
The JWT string.
Returns
Section titled “Returns”void