- 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/