功能特色 程式碼
立即開始

Rust Web 框架

輕巧。精緻。
極致效能。

用最少的程式碼,建構生產級 Web 應用程式。 Hotaru 將 Rust 的卓越效能與優雅的 API 設計完美融合。

21,858 請求/秒
<4ms 延遲
33% 記憶體節省
main.rs
use hotaru::prelude::*;

LServer!(APP = Server::new()
    .binding("127.0.0.1:3000")
    .build());

endpoint! {
    APP.url("/"),
    pub hello<HTTP> {
        text_response("Hello, Hotaru!")
    }
}

為何選擇 Hotaru

所需盡有。
多餘皆無。

簡潔透明

所見即所得。沒有隱藏的複雜性,沒有意外的行為。只有簡潔、明確的 Rust 程式碼。

多協定支援

HTTP、WebSocket 與自訂 TCP 協定。一個框架,無限可能。

全端就緒

內建 Akari 模板引擎,輕鬆實現伺服器端算繪。

預設安全

請求驗證、請求主體限制、方法白名單,開箱即用。

強大中介軟體

非同步中介軟體,支援協定感知的繼承機制。

正規表達式路由

靈活的模式比對,支援型別化參數。

開發體驗

寫得更少。
交付更多。

Hello World
use hotaru::prelude::*;
use hotaru::http::*;

LServer!(APP = Server::new()
    .binding("127.0.0.1:3000")
    .build());

endpoint! {
    APP.url("/"),
    pub index<HTTP> {
        text_response("Hello, World!")
    }
}

#[tokio::main]
async fn main() {
    APP.clone().run().await;
}
Path Parameters
endpoint! {
    APP.url("/users/<int:id>"),
    pub get_user<HTTP> {
        let user_id = req.pattern("id")
            .unwrap_or("unknown".to_string());

        json_response(object!({
            id: user_id,
            name: "Alice",
            email: "alice@example.com"
        }))
    }
}

// GET /users/42 → {"id":"42","name":"Alice",...}
Akari Templates
endpoint! {
    APP.url("/profile"),
    pub profile<HTTP> {
        akari_render!(
            "profile.html",
            name = "Alice",
            email = "alice@example.com",
            posts = ["First post", "Second post"]
        )
    }
}

// Server-rendered HTML with type-safe templates
Async Middleware
middleware! {
    pub Logger<HTTP> {
        let start = std::time::Instant::now();
        let path = req.path().to_string();

        let req = next(req).await?;

        println!("[LOG] {} - {:?}",
            path, start.elapsed());

        Ok(req)
    }
}

LServer!(APP = Server::new()
    .binding("127.0.0.1:3003")
    .single_protocol(
        ProtocolBuilder::new(HTTP::server(HttpSafety::default()))
            .append_middleware::<GlobalLogger>()
            .append_middleware::<GlobalMetrics>()
    )
    .build());

準備好建構
精彩之作了嗎?

幾秒鐘即可開始使用 Hotaru。只需一條指令。

cargo add hotaru