Toucan is a micro webframework for Donna. Routes are function chains β pipe a request through method filters, path matchers, and response functions using Donna's |> operator. Handlers are plain fn(Ctx) -> Ctx functions: no macros, no magic, no hidden wiring.
WebSockets are first-class. serve_chat adds real-time messaging to any app in a single call, and serve_with_chat lets the same app keep shared state such as sessions.
You need Donna installed. Create a new app:
donna new <app>Add toucan to your donna.toml:
toucan = { git = "https://github.com/NikolasSkyl/toucan", version = ">=0.1.0 and <1.0.0" }import toucan
fn handler(c: toucan.Ctx) -> toucan.Ctx:
c
|> toucan.try(home)
|> toucan.landing_page
|> toucan.not_found
fn home(c: toucan.Ctx) -> toucan.Ctx:
c
|> toucan.get
|> toucan.path("/hello")
|> toucan.html("<h1>Hello from Toucan!</h1>")
pub fn main() -> Nil:
toucan.serve(handler, 8080)
Run it:
donna run- Pipeline routing β compose routes with
|>, each step is a plain function - URL parameters β
:namecaptures viatoucan.param(c, "name") - Forms & query strings β
form_fieldandquery_parambuilt in - WebSockets β
serve_wsfor echo servers,serve_chatfor broadcast - Sessions β cookie-backed session helpers under
toucan/session - Static files β serve a directory with
static_dir - CORS & security headers β one-call
cors,csp,secure_headers - Request logger β coloured output with
serve_logged - Redirects & custom status β
redirect,respond
Full documentation here.
Runnable examples live in examples/:
basicβ routing and formstodo_sqliteβ server-rendered todos with SQLite and Mustachetodo_json_apiβ JSON API with SQLite storageauth_loginβ registration, login, sessions, and protected pagesfile_uploadβ text and image uploadsurl_shortenerβ short links and redirectshtmx_todosβ partial HTML updates with htmxchat_sessionsβ WebSocket chat with named users
Each example runs on port 8000:
cd examples/basic
donna runMIT

