Documentation

Everything you need to know to build powerful functions.

The `request` Object

Your function receives a `request` object containing all the details of the incoming HTTP request. It has the following structure:

{
    "method": "GET",
    "headers": { ... },
    "url": "http://...",
    "path": "/sub/path",
    "query": { "param": "value" },
    "json": { "key": "value" },
    "form": { "field": "value" },
    "text": "plain text body"
}

The `environment` Object

The `environment` object is a mutable JSON object that persists across function executions. You can read from it and write to it to maintain state.

// Example: A simple counter
async (req) => {
    if (!environment.counter) {
        environment.counter = 0;
    }
    environment.counter++;
    return JsonResponse({ count: environment.counter });
}

Response Helpers

Several helper functions are available globally to make creating responses easier:

  • `Response(body, headers, status)`: The base response function.
  • `JsonResponse(body, headers, status)`: Creates a response with `Content-Type: application/json`.
  • `HtmlResponse(body, headers, status)`: Creates a response with `Content-Type: text/html`.
  • `TextResponse(body, headers, status)`: Creates a response with `Content-Type: text/plain`.

Console Logging

You can use `console.log()` and `console.error()` within your function. The output will be captured and displayed in the function's logs, which you can view in your dashboard.

Supported Runtimes

You can write your functions in JavaScript, Deno, or Python. The runtime is determined by the file extension of your entrypoint.

JavaScript (Node.js)

The JavaScript runtime uses Node.js. You can use modern JavaScript features, including `async/await`. NPM packages are not supported.

// Example: A simple JavaScript function
async (req) => {
    return JsonResponse({ message: "Hello from JavaScript!" });
}

Deno

The Deno runtime offers a modern, secure, and TypeScript-first environment. You can import modules directly from URLs.

// Example: A simple Deno function
import { serve } from "https://deno.land/std@0.140.0/http/server.ts";

async (req) => {
    return JsonResponse({ message: "Hello from Deno!" });
}

Python

The Python runtime uses Python 3. You can use the standard library, but third-party packages are not supported.

# Example: A simple Python function
async def main(req):
    return JsonResponse({"message": "Hello from Python!"})