特徴 コード
はじめる

実験的な Rust ネットワークフレームワーク

小さく。
心地よく。

プロトコル指向。

現在は Tokio 上で HTTP/1.1 の Server と Client を構築でき、対称的な Endpoint / Outpoint API で受信・送信処理を整理できます。 Hotaru 0.8.x は pre-1.0 の実験段階にあり、 現在も堅牢化を進めています。

main.rs
use hotaru::http::*;
use hotaru::prelude::*;

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

fn main() {
    run_server!(APP);
}

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

現在の機能

現在の Hotaru が提供するもの。
プロトコル指向のコアを中心に設計。

方針のあるデフォルト

標準パスでは trans Endpoint DSL と自動登録を使用し、明示的な登録と実験的な手動定義を代替手段として残しています。

プロトコル指向のコア

メインワークスペースでは HTTP/1.1 と HTTPS を提供しています。Protocol trait はカスタム実装の拡張ポイントです。

サーバーレンダリング用 Web ヘルパー

Akari テンプレートとオプションの Web ミドルウェアにより、Tokio/HTTP のサーバーレンダリングアプリケーションを構築できます。

設定可能なリクエスト制限

HttpSafety でボディ、Header、行長、メソッドの制限を設定できます。0.8.x の HTTP スタックは現在も堅牢化中です。

Server + Client

Endpoint は受信処理を担い、Outpoint は送信処理を整理します。両者は同じプロトコルとランタイムモデルを共有します。

型付き・パターンルーティング

リテラル、型付き、正規表現、ワイルドカード、catch-all のルートセグメントに対応します。

開発者体験

標準となる一つのパス。
必要なときは明示的な選択肢も。

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

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

fn main() {
    run_server!(APP);
}

endpoint! {
    APP.url("/"),
    pub index<HTTP> {
        text_response("Hello, Hotaru!")
    }
}
Path Parameters
endpoint! {
    APP.url("/users/<int:id>"),
    pub get_user<HTTP> {
        let user_id = req.param("id")
            .unwrap_or("unknown".to_string());

        akari_json!({
            id: user_id,
            name: "Alice",
            email: "[email protected]"
        })
    }
}

// GET /users/42 -> {"id":"42","name":"Alice",...}
Akari Templates
endpoint! {
    APP.url("/profile"),
    pub profile<HTTP> {
        akari_render!(
            "profile.html",
            name = "Alice",
            email = "[email protected]",
            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();
        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::<Logger>()
    )
    .build());

現在の
Tokio + HTTP/1.1 パスを試す。

Hotaru を追加し、上の検証済み Quickstart をコピーして、ローカルでサーバーを実行してください。Hotaru 0.8.x は引き続き実験段階です。

cargo add hotaru