2021-08-18 00:49:01 +02:00
|
|
|
//! Run with
|
|
|
|
|
//!
|
|
|
|
|
//! ```not_rust
|
2023-03-10 12:02:11 +01:00
|
|
|
//! cargo run -p example-hello-world
|
2021-08-18 00:49:01 +02:00
|
|
|
//! ```
|
|
|
|
|
|
2021-11-02 13:07:34 +01:00
|
|
|
use axum::{response::Html, routing::get, Router};
|
|
|
|
|
|
2021-08-18 00:49:01 +02:00
|
|
|
#[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-08-18 00:49:01 +02:00
|
|
|
|
2021-11-02 13:07:34 +01:00
|
|
|
// run it
|
2023-03-22 23:42:14 +01:00
|
|
|
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
|
2021-08-18 00:49:01 +02:00
|
|
|
.await
|
|
|
|
|
.unwrap();
|
2023-03-22 23:42:14 +01:00
|
|
|
println!("listening on {}", listener.local_addr().unwrap());
|
2025-12-28 09:25:50 +01:00
|
|
|
axum::serve(listener, app).await;
|
2021-08-18 00:49:01 +02:00
|
|
|
}
|
2021-11-02 13:07:34 +01:00
|
|
|
|
|
|
|
|
async fn handler() -> Html<&'static str> {
|
|
|
|
|
Html("<h1>Hello, World!</h1>")
|
|
|
|
|
}
|