功能 代碼
即刻開始

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;
}
路徑參數
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 模板
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
非同步中間件
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