[{"data":1,"prerenderedAt":4},["ShallowReactive",2],{"AMKAkEED6p":3},"# Lithe\n\n[![Version](https://img.shields.io/badge/version-0.1.0-green.svg)](https://github.com/JoshuaPurtell/lithe/releases)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)\n[![Lean 4](https://img.shields.io/badge/Lean-4.27.0-orange)](https://lean-lang.org/)\n\nA lightweight web framework for **[Lean 4](https://lean-lang.org/)** with an Axum-inspired router, type-safe extractors, and middleware.\n\n> **What is Lean 4?** [Lean](https://lean-lang.org/) is a functional programming language and theorem prover developed by Microsoft Research. It combines a powerful type system with the ability to write mathematical proofs, making it ideal for building verified, high-assurance software.\n\n## Features\n\n- **Router** — Path parameters, query parsing, method routing\n- **Extractors** — JSON, Form, Path, Query, Headers, Auth, State\n- **Middleware** — CORS, CSRF, rate limiting, timeouts, logging, metrics\n- **Streaming** — SSE, WebSocket, chunked responses\n- **Storage** — SQLite integration via [lean-sqlite](https://github.com/leanprover/leansqlite)\n\n## Installation\n\nAdd to your `lakefile.lean`:\n\n```lean\n-- Latest stable release (recommended)\nrequire lithe from git \"https://github.com/JoshuaPurtell/lithe\" @ \"v0.1.0\"\n\n-- Or track main branch (latest features, may be unstable)\nrequire lithe from git \"https://github.com/JoshuaPurtell/lithe\" @ \"main\"\n```\n\nThen build:\n\n```bash\nlake build\n```\n\n> **Note:** Requires Lean 4.27.0+ (see `lean-toolchain`).\n\n### Versioning\n\nLithe follows [Semantic Versioning](https://semver.org/). Pin to a specific version tag (e.g., `v0.1.0`) for stability in production.\n\n## Quick Start\n\n```lean\nimport Lithe\n\nopen Lithe\n\ndef hello : Handler :=\n  fun _ => pure (Response.text \"Hello, World!\")\n\ndef app : Router :=\n  Router.empty\n    |> Router.get \"/hello\" hello\n\n-- Test in-memory\n#eval Lithe.run app { method := .GET, path := \"/hello\", query := \"\", headers := #[], body := .empty }\n```\n\n## Running with HTTP (Rust Shim)\n\nFor production HTTP serving, use the Rust shim:\n\n```bash\ncd examples/hello\nlake build\n\ncd ../../rust/lithe-shim\ncargo run\n```\n\n```bash\ncurl http://127.0.0.1:3000/hello\n# Hello, World!\n```\n\n### Environment Variables\n\n| Variable | Description | Default |\n|----------|-------------|---------|\n| `LITHE_BIND` | Bind address | `127.0.0.1:3000` |\n| `LITHE_RUST_TIMEOUT_MS` | Request timeout (ms) | none |\n\n## Middleware Example\n\n```lean\nimport Lithe\n\nopen Lithe\n\ndef app : Router :=\n  Router.empty\n    |> Router.withMiddleware (cors { origins := #[\"https://example.com\"] })\n    |> Router.withMiddleware (rateLimit { maxRequests := 100, windowMs := 60000 })\n    |> Router.get \"/api/data\" dataHandler\n```\n\n## Project Structure\n\n```\nLithe/\n├── Core/           # Handler, Context, Error types\n├── Http/           # Request, Response, Status, WebSocket, SSE\n├── Router/         # Path matching, routing\n├── Extractor/      # JSON, Form, Path, Query extractors\n├── Middleware/     # CORS, CSRF, Auth, Logging, etc.\n├── Storage/        # SQLite integration\n└── FFI/            # Rust shim exports\n```\n\n## Examples\n\n| Example | Description |\n|---------|-------------|\n| `examples/hello` | Basic \"Hello World\" |\n| `examples/streaming` | Chunked response streaming |\n| `examples/sse` | Server-Sent Events |\n| `examples/websocket` | WebSocket echo server |\n| `examples/kitchen_sink` | All features combined |\n\n## Security Notes\n\n- **TLS**: Not handled by Lithe. Use a reverse proxy (Caddy/Nginx) or add TLS at the Rust layer.\n- **CSRF**: Use the `csrf` middleware for cookie-based auth.\n- **Sessions**: Set `Secure`, `HttpOnly`, `SameSite=Strict` on cookies.\n\n## Demo: Lean Crafter\n\nAs a demonstration, I've built [Crafter](https://github.com/JoshuaPurtell/lean-crafter)—a 2D survival game—entirely in Lean 4 and hosted it on the web using Lithe.\n\n🎮 **[Play it live](https://lean-crafter-production.up.railway.app/)** | 📦 **[Source code](https://github.com/JoshuaPurtell/lean-crafter)**\n\n## License\n\nMIT — see [LICENSE](LICENSE)\n",1780846768560]