Everything you need to know to build powerful functions.
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 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 });
}
Several helper functions are available globally to make creating responses easier:
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.
You can write your functions in JavaScript, Deno, or Python. The runtime is determined by the file extension of your entrypoint.
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!" });
}
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!" });
}
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!"})