Overview
Functions module for invoking custom backend functions. This module allows you to invoke the custom backend functions defined in the app.Authentication Modes
This module is available to use with a client in all authentication modes:- Anonymous or User authentication (
base44.functions): Functions are invoked with the current user’s permissions. Anonymous users invoke functions without authentication, while authenticated users invoke functions with their authentication context. - Service role authentication (
base44.asServiceRole.functions): Functions are invoked with elevated admin-level permissions. The function code receives a request with admin authentication context.
Generated Types
If you’re working in a TypeScript project, you can generate types from your backend functions to get autocomplete on function names when callinginvoke(). See the Dynamic Types guide to get started.
Methods
invoke()
invoke(Invokes a custom backend function by name. Sends a POST request to a custom backend function deployed to the app. The function receives the provided data as named parameters and returns the result. If any parameter is afunctionName,data?):Promise<any>
File object, the request will automatically be
sent as multipart/form-data. Otherwise, it will be sent as JSON.
For streaming responses, non-POST methods, or raw response access, use fetch() instead.
Parameters
Properties
Properties
Returns
Promise<any>
Promise resolving to the function’s response. The data property contains the data returned by the function, if there is any.
Examples
fetch()
fetch(Performs a direct HTTP request to a backend function path and returns the nativepath,init?):Promise<Response>
Response.
Use fetch() when you need low-level control that invoke() doesn’t provide, such as:
- Streaming responses, like SSE, chunked text, or NDJSON
- Custom HTTP methods, like PUT, PATCH, or DELETE
- Raw response access, including status codes, headers, and binary bodies
Parameters
Properties
Properties
Function path. Leading slash is optional, so
/chat and chat are equivalent. For example, '/streaming_demo' or 'reports/export'.Optional
RequestInit options such as method, headers, body, and signal. Auth headers are added automatically.Returns
Promise<Response>
Promise resolving to a native Response.
Examples
Type Definitions
FunctionName
FunctionName = keyofUnion of all function names from theFunctionNameRegistryextendsnever?string: keyofFunctionNameRegistry
FunctionNameRegistry. Defaults to string when no types have been generated.
Example
FunctionNameRegistry
Registry of function names. The
types generate command fills this registry, then FunctionName resolves to a union of the keys.
