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.