Rust Web フレームワーク
最小限のコードで、本番環境対応の Web アプリケーションを構築。 Hotaru は Rust のパフォーマンスと、心地よい API を融合します。
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 テンプレートエンジンを搭載。
リクエスト検証、ボディサイズ制限、メソッドホワイトリストを標準搭載。
プロトコル対応の継承機能を備えた非同期ミドルウェア。
型付きパラメータによる柔軟なパターンマッチング。
開発者体験
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",...}
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());