跳到正文
DEV Community· Cooper Ransom·· 7 天前AI 評分45

Wisp:一個快速、有趣的 Rust 網頁框架

Wisp - A fast, fun web framework for Rust

AI 導讀

Wisp 是作者為 Rust 開發的網頁框架,現為 MIT 授權的預發佈版 1.0.0-pre.3,要求 Rust 1.89 或以上。框架以資料夾對應 URL,模板編譯成 Rust,整個應用程式連同樣式及靜態檔案打包成單一二進制檔。測試小型應用程式使用 477 tokens,Nuxt 則使用 1,043 tokens;作者測量的技術堆疊中,Wisp 少用 2.2x 至 3.9x tokens。

正文

Cooper Ransom

Hi, I built Wisp, a web framework for Rust. Here is a 90-second video of it: https://www.youtube.com/watch?v=g0LPPzrQux8

The idea: a folder is a URL, and its +page.wisp file is the page. The top of the file is a short block of Rust that loads data and handles forms, and the rest is markup. The templates compile to Rust, so the compiler checks your markup, and the whole app (styles and static files too) ships as one binary.

  ---
  let name = cx.query_or("name", "world".to_string());
  ---
  <h1>Hello, ${name}!</h1>

Things I cared about:

  • Forms work with JavaScript off. #[action] handlers validate on the server, and use:enhance updates the page in place when scripts are on.

  • Reactivity lives in the same file: on:click="count++" and {:count}, no separate component.

  • wisp npm add gets a package for browser code, with no Node install.

  • wisp mcp gives coding agents the docs and a checker, so an agent can read how Wisp works and check its own changes.

  • Hosting: one binary on your own server (wisp host keeps it running), static HTML, or a build for Cloudflare, Deno Deploy, Vercel, Netlify, AWS Lambda, Bun and Node.

  • No auth or database layer, on purpose. Wisp gives tools (tables, signed cookies, hooks, uploads) and leaves those choices to you.

On AI-written code: the small test app is 477 tokens in Wisp and 1,043 in Nuxt, 2.2x to 3.9x fewer across the stacks I measured (release 1.0.0-pre.3). Method and apps: https://wispweb.dev/docs/tokens/

Status: this is a pre-release (1.0.0-pre.3), MIT licensed, Rust 1.89 or later. The source is at https://code.wispweb.dev/wispdev/wisp for now. It moves to GitHub and crates.io with 1.0.

To try it:

  cargo install --git https://wisp.ar0.eu/ wisp-web
  wisp new my-app
  cd my-app
  wisp dev

I'd love to hear what breaks, what feels wrong, and what you'd need before you used it for a real project.

來源:DEV Community · dev.to