Skip to content

Instantly share code, notes, and snippets.

@masakielastic
Last active February 20, 2026 23:28
Show Gist options
  • Select an option

  • Save masakielastic/8294e036def805bc88c839e67cfc9419 to your computer and use it in GitHub Desktop.

Select an option

Save masakielastic/8294e036def805bc88c839e67cfc9419 to your computer and use it in GitHub Desktop.
Composer で Rust 製の HTTP サーバーの CLI を管理する

 Composer で Rust 製の HTTP サーバーの CLI を管理する

構成

  • composer.json
  • rust/Cargo.toml
  • rust/src/main.rs

Cargo.toml

[package]
name = "my_http_server"
version = "0.1.0"
edition = "2021"

[dependencies]
axum = "0.8"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }

src/main.rs

use axum::{routing::get, Router};

async fn root() -> &'static str {
    "ok\n"
}

#[tokio::main]
async fn main() {
    let app = Router::new().route("/", get(root));

    let addr = "127.0.0.1:3000";
    let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
    println!("listening on http://{addr}");
    axum::serve(listener, app).await.unwrap();
}

composer.json

{
  "name": "example/my-app",
  "type": "project",
  "require": {},
  "scripts": {
    "rust:server": "cargo run --manifest-path rust/Cargo.toml",
    "rust:server:release": "cargo run --release --manifest-path rust/Cargo.toml",
    "rust:fmt": "cargo fmt --manifest-path rust/Cargo.toml",
    "rust:clippy": "cargo clippy --manifest-path rust/Cargo.toml -- -D warnings",
    "rust:test": "cargo test --manifest-path rust/Cargo.toml"
  }
}

ビルド&起動

composer run rust:server

別のターミナルでアクセス

curl http://127.0.0.1:3000/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment