Import
You can import and use this package with:Usage
You can use this library by passing the path to the function you want to call and any body or fetch options you want to apply (optional):fetch
method instead:
Error handling
The SDK will throw errors in most operations if the request returns a status >=300 or if the request fails entirely (i.e., due to network errors). The type of the error will be aFetchError<T>
:
Error
type so if you want to just log the error you can
do so like this:
Interfaces
Client
Functions client interface providing methods for executing serverless function callsProperties
baseURL
Methods
fetch()
- Object if the response is application/json
- string text string if the response is text/*
- Blob if the response is any other type
Type Parameters
Type Parameter | Default type |
---|---|
T | unknown |
Parameters
Parameter | Type | Description |
---|---|---|
path | string | The path to the serverless function |
options? | RequestInit | Additional fetch options to apply to the request |
Returns
Promise
<FetchResponse
<T
>>
Promise with the function response and metadata.
post()
Content-Type
and ‘Accept’ headers to application/json
and
automatically stringifying the body.
For a more generic request, use the fetch
method instead.
Type Parameters
Type Parameter | Default type |
---|---|
T | unknown |
Parameters
Parameter | Type | Description |
---|---|---|
path | string | The path to the serverless function |
body? | unknown | The JSON body to send in the request |
options? | RequestInit | Additional fetch options to apply to the request |
Returns
Promise
<FetchResponse
<T
>>
Promise with the function response and metadata
Functions
createAPIClient()
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
baseURL | string | undefined | Base URL for the functions endpoint |
chainFunctions | ChainFunction [] | [] | Array of middleware functions for the fetch chain |
Returns
Client
Functions client with fetch method