Skip to content

Latest commit

Β 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

toucan

toucan

Donna - toucan Test status

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.

Install

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" }

Quick Start

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

toucan landing page

Features

  • Pipeline routing β€” compose routes with |>, each step is a plain function
  • URL parameters β€” :name captures via toucan.param(c, "name")
  • Forms & query strings β€” form_field and query_param built in
  • WebSockets β€” serve_ws for echo servers, serve_chat for 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

Documentation

Full documentation here.

Examples

Runnable examples live in examples/:

  • basic β€” routing and forms
  • todo_sqlite β€” server-rendered todos with SQLite and Mustache
  • todo_json_api β€” JSON API with SQLite storage
  • auth_login β€” registration, login, sessions, and protected pages
  • file_upload β€” text and image uploads
  • url_shortener β€” short links and redirects
  • htmx_todos β€” partial HTML updates with htmx
  • chat_sessions β€” WebSocket chat with named users

Each example runs on port 8000:

cd examples/basic
donna run

Licence

MIT

About

πŸ¦β€β¬› A micro web framework for Donna Language

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages