Protected
Readonly
baseURLThe base URL for all API requests. Must be defined in subclasses.
Protected
afterThis method is called after the response is received. It can be used to process or inspect the response before returning it.
The response object that was received.
A promise that resolves to the (possibly processed) response.
Protected
beforeThis method is called before the request is sent. It can be used to modify the request before it is sent (e.g., adding headers).
The request object that will be sent.
A promise that resolves to the (possibly modified) request.
Sends a DELETE
request to the specified path.
The path to send the request to, relative to baseURL
.
Optional
init: Omit<RequestInit, "method">Optional request options, excluding the HTTP method.
A promise that resolves to the response from the request.
Sends a fetch request to the specified path, using the provided
RequestInit
options.
The path to send the request to, relative to baseURL
.
Optional
init: RequestInitOptional request options.
A promise that resolves to the response from the request.
Sends a GET
request to the specified path.
The path to send the request to, relative to baseURL
.
Optional
init: Omit<RequestInit, "method">Optional request options, excluding the HTTP method.
A promise that resolves to the response from the request.
Sends a PATCH
request to the specified path.
The path to send the request to, relative to baseURL
.
Optional
init: Omit<RequestInit, "method">Optional request options, excluding the HTTP method.
A promise that resolves to the response from the request.
Sends a POST
request to the specified path.
The path to send the request to, relative to baseURL
.
Optional
init: Omit<RequestInit, "method">Optional request options, excluding the HTTP method.
A promise that resolves to the response from the request.
Sends a PUT
request to the specified path.
The path to send the request to, relative to baseURL
.
Optional
init: Omit<RequestInit, "method">Optional request options, excluding the HTTP method.
A promise that resolves to the response from the request.
The
APIClient
class provides a basic HTTP client for making API requests. It includes methods for makingGET
,POST
,PUT
,PATCH
, andDELETE
requests.Subclasses should define the
baseURL
to specify the root URL for all requests.The class allows for customization of the request and response through the
before
andafter
hooks, which can be overridden in subclasses to modify behavior before sending a request or after receiving a response.Example