mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-16 00:00:18 +02:00
25 lines
561 B
Rust
25 lines
561 B
Rust
//! Run with
|
|
//!
|
|
//! ```not_rust
|
|
//! cargo run -p example-hello-world
|
|
//! ```
|
|
|
|
use axum::{response::Html, routing::get, Router};
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
// build our application with a route
|
|
let app = Router::new().route("/", get(handler));
|
|
|
|
// run it
|
|
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
|
|
.await
|
|
.unwrap();
|
|
println!("listening on {}", listener.local_addr().unwrap());
|
|
axum::serve(listener, app).await;
|
|
}
|
|
|
|
async fn handler() -> Html<&'static str> {
|
|
Html("<h1>Hello, World!</h1>")
|
|
}
|