Skip to main content
Backend functions let you run custom backend code in a secure, isolated environment. Use functions to implement business logic that shouldn’t run in the browser, connect to third-party APIs with protected credentials, process webhooks, or extend your app with custom endpoints. Backend functions run on Deno, a modern TypeScript runtime. Call functions from your frontend using the SDK, which handles authentication automatically. Each function also gets its own HTTP endpoint for webhooks and external integrations.

Create and deploy functions

Create backend functions as TypeScript files in your project’s functions directory and deploy them with functions deploy or deploy. By default the functions directory is base44/functions/, but you can customize the path in your project configuration. Each function requires its own subdirectory containing two files:
functions
<function-name>
function.jsonc
index.ts

function.jsonc

The configuration file defines the function’s name and entry point:
{
  "name": "sendWelcomeEmail",
  "entry": "index.ts"
}
PropertyDescription
nameUnique identifier for the function. Used when invoking via SDK or HTTP.
entryThe TypeScript file containing the function code.

index.ts

The code file contains your function logic. Functions must use the Deno.serve() wrapper and return Response objects:
import { createClientFromRequest } from "npm:@base44/sdk";

Deno.serve(async (req) => {
  try {
    const base44 = createClientFromRequest(req);
    const user = await base44.auth.me();

    if (!user) {
      return Response.json({ error: "Unauthorized" }, { status: 401 });
    }

    const { name } = await req.json();

    return Response.json({
      message: `Hello, ${name || user.full_name}!`,
    });
  } catch (error) {
    return Response.json({ error: error.message }, { status: 500 });
  }
});

Call functions

Call backend functions from your frontend using the SDK, or via HTTP for webhooks and external integrations.

Via the SDK

Use base44.functions.invoke() to call functions from your frontend. The SDK handles authentication automatically, passing the current user’s credentials to your function.
import { base44 } from "@/api/base44Client";

const response = await base44.functions.invoke("sendWelcomeEmail", {
  name: "Alice"
});

Via HTTP

Each deployed function gets an HTTP endpoint at:
https://<your-app-domain>/functions/<function-name>
This is useful for:
  • Webhooks: Receive callbacks from external services like Stripe or GitHub.
  • External integrations: Allow other systems to interact with your app.
  • Testing: Call functions directly with tools like cURL or Postman.
Example usage
curl -X POST https://your-app.base44.app/functions/sendWelcomeEmail \
  -H "Content-Type: application/json" \
  -d '{"name": "Alice"}'
When calling functions via direct HTTP (like cURL or webhooks), there’s no authenticated user context. Use asServiceRole for all operations in these cases.

Use the SDK in functions

Inside your backend functions, you can access your app’s data, authentication, and integrations through the Base44 SDK. Use createClientFromRequest() to create a client from the incoming request. The authentication context depends on how the function was called:
  • When called via the SDK from your frontend: The user’s authentication is passed through automatically. You can access the current user with base44.auth.me() and perform operations with their permissions. For admin-level operations, use asServiceRole.
  • When called via direct HTTP (cURL, webhooks, external services): There’s no authenticated user, so use asServiceRole for all operations.

Connect to third-party APIs

Backend functions are one of several ways to connect to third-party APIs. They’re ideal when you need full control over requests or want to store API keys securely as environment variables.

See also