Hello World
The simplest Thunder edge function. It responds to every request with a plain-text greeting.
import { TextResponse } from "thunder:http";
export default function handler(req: Request) { return TextResponse("Hello from edge function!").toResponse();}The export default function pattern is the preferred way to define a Thunder edge function with a single handler. Thunder invokes the exported function for every inbound HTTP request routed to this function. The function receives a standard Request object and must return a Response (or a Promise<Response>).
The TextResponse helper from the thunder:http module creates a response with content-type: text/plain automatically. You can also chain .status() and .header() before .toResponse() for further customization.
Run locally
Section titled “Run locally”Start the function with hot-reload:
thunder watch --path ./examples/hello/hello.tsThen test it:
curl http://localhost:9000/# Hello from edge function!Bundle
Section titled “Bundle”Create an eszip bundle for deployment:
thunder bundle --entrypoint ./examples/hello/hello.ts --output ./hello.eszipOr a snapshot bundle (faster cold starts):
thunder bundle --entrypoint ./examples/hello/hello.ts --output ./hello.snapshot.bundle --format snapshotDeploy
Section titled “Deploy”Deploy the bundle to a running Thunder server via the admin API:
curl -X POST http://localhost:9001/functions \ -H "Content-Type: application/octet-stream" \ -H "X-Function-Name: hello" \ --data-binary @./hello.eszipInvoke
Section titled “Invoke”Once deployed, invoke the function through the ingress listener:
curl http://localhost:9000/hello# Hello from edge function!What to try next
Section titled “What to try next”- Return JSON instead of plain text — see JSON API.
- Use the
export defaultobject pattern with HTTP method handlers — see RESTful CRUD. - Explore all 30 examples in the Examples overview.