Files
axum/examples/hello-world/src/main.rs
T

25 lines
561 B
Rust
Raw Normal View History

//! Run with
//!
//! ```not_rust
//! cargo run -p example-hello-world
//! ```
2021-11-02 13:07:34 +01:00
use axum::{response::Html, routing::get, Router};
#[tokio::main]
async fn main() {
2021-11-02 13:07:34 +01:00
// build our application with a route
let app = Router::new().route("/", get(handler));
2021-11-02 13:07:34 +01:00
// run it
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
.await
.unwrap();
println!("listening on {}", listener.local_addr().unwrap());
2025-12-28 09:25:50 +01:00
axum::serve(listener, app).await;
}
2021-11-02 13:07:34 +01:00
async fn handler() -> Html<&'static str> {
Html("<h1>Hello, World!</h1>")
}