Use axum by adding it to your Cargo.toml alongside tokio and defining a handler function that returns a response.
use axum::{routing::get, Router};
#[tokio::main]
async fn main() {
let app = Router::new().route("/", get(handler));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
async fn handler() -> &'static str {
"Hello, World!"
}
Add these dependencies to Cargo.toml:
[dependencies]
axum = "0.7"
tokio = { version = "1.51.1", features = ["full"] }