Skip to content

Examples

Thunder includes 30 ready-to-run example edge functions in the examples/ directory of the repository. Each example lives in its own subdirectory with a single TypeScript entry file.

Start any example with the watch command, which reloads automatically on file changes:

Terminal window
thunder watch --path ./examples/hello/hello.ts

Or serve all examples and switch between them by path:

Terminal window
thunder watch --path ./examples
ExampleDirectoryDescription
helloexamples/hello/Basic hello world — the simplest possible edge function.
json-apiexamples/json-api/REST API with JSON routes (GET /api/users, POST /api/echo).
restful-defaultexamples/restful-default/RESTful CRUD using export default object pattern with thunder:http helpers.
all-methods-defaultexamples/all-methods-default/Default function handler with GenericResponse supporting all HTTP methods.
basic-authexamples/basic-auth/HTTP Basic Authentication with timing-safe credential comparison.
corsexamples/cors/CORS handling with configurable allowed origins, methods, and headers.
websocketexamples/websocket/WebSocket server with echo and greeting logic.
server-sent-eventsexamples/server-sent-events/SSE streaming using ReadableStream with typed events.
streaming-dataexamples/streaming-data/Chunked response streaming with ReadableStream.
cachingexamples/caching/Cache-Control headers and conditional request handling.
compression-streamexamples/compression-stream/Gzip and deflate compression using CompressionStream / DecompressionStream.
form-handlingexamples/form-handling/FormData processing for multipart and URL-encoded forms.
middlewareexamples/middleware/Request/response middleware pattern (logging, auth, timing).
rate-limitingexamples/rate-limiting/In-memory rate limiting with sliding window.
security-headersexamples/security-headers/Security header configuration (CSP, HSTS, X-Frame-Options, etc.).
url-redirectexamples/url-redirect/URL redirection with status code control.
urlpattern-routingexamples/urlpattern-routing/URLPattern-based routing for clean path matching.
web-crypto-apiexamples/web-crypto-api/Web Crypto API usage (hashing, signing, encryption).
wasmexamples/wasm/WebAssembly module loading and execution (Fibonacci calculator).
preact-ssrexamples/preact-ssr/Server-side rendering with Preact-style components.
html-pageexamples/html-page/Serve a full HTML page from an edge function.
http-requestexamples/http-request/Outbound HTTP requests using fetch().
error-handlingexamples/error-handling/Error handling patterns and structured error responses.
abort-controllerexamples/abort-controller/AbortController for request cancellation and timeouts.
data-processingexamples/data-processing/Data transformation and processing pipelines.
generatorsexamples/generators/Generator functions and async iterators.
intl-apiexamples/intl-api/Internationalization API (Intl.DateTimeFormat, Intl.NumberFormat).
performance-apiexamples/performance-api/Performance API for timing measurements.
request-modificationexamples/request-modification/Request cloning and header modification.
transform-streamexamples/transform-stream/TransformStream for on-the-fly data transformation.

You can bundle any example into a deployable artifact:

Terminal window
thunder bundle --entrypoint ./examples/hello/hello.ts --output ./hello.eszip

Or as a snapshot bundle:

Terminal window
thunder bundle --entrypoint ./examples/hello/hello.ts --output ./hello.snapshot.bundle --format snapshot

See the individual example pages for more details on Hello World, JSON API, RESTful CRUD, and more.