特性 代码
立即开始

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