PayWeavePayWeaveBack to Home
Functions

Function Handlers

A handler is a single endpoint within a Function. Each handler has its own path, price, allowed methods, and TypeScript code. A Function can contain multiple handlers, each serving a different purpose.

Creating a handler

From your Function detail page, click Add Handler and configure:

FieldDescription
NameA human-readable label for the handler
PathThe URL path segment (e.g. /translate)
PriceCost per request in USD
MethodsAllowed HTTP methods (GET, POST, etc.)

Writing handler code

The built-in code editor provides a TypeScript environment. Your handler exports a default function that receives a Request and returns a Response:

TypeScript
export default async function handler(req: Request): Promise<Response> {
  const body = await req.json();

  const result = await fetch('https://api.example.com/process', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ input: body.text }),
  });

  const data = await result.json();
  return Response.json({ output: data.result });
}

Accessing request data

The Request object is a standard Web API Request. Use it to read headers, query parameters, and body:

TypeScript
export default async function handler(req: Request): Promise<Response> {
  // Query params
  const url = new URL(req.url);
  const query = url.searchParams.get('q');

  // Headers
  const apiVersion = req.headers.get('x-api-version');

  // JSON body (for POST/PUT)
  const body = await req.json();

  return Response.json({ query, apiVersion, received: body });
}

Environment variables

Handlers can access secrets and configuration via process.env. See the Secrets section for how to manage encrypted environment variables.

TypeScript
export default async function handler(req: Request): Promise<Response> {
  const apiKey = process.env.OPENAI_API_KEY;
  // use apiKey to call external services
  return Response.json({ status: 'ok' });
}
The code editor supports autocomplete and type checking. Changes are deployed instantly when you click Save - no build pipeline required.

Pricing per handler

Each handler has its own price, letting you charge differently for lightweight reads versus expensive computations. Prices are set in USD with a minimum of 0.0001.