mirror of
https://github.com/tokio-rs/axum.git
synced 2025-09-29 05:50:49 +00:00
27 lines
598 B
Rust
27 lines
598 B
Rust
//! Run with
|
|
//!
|
|
//! ```not_rust
|
|
//! cd examples && cargo run -p example-hello-world
|
|
//! ```
|
|
|
|
use axum::{response::Html, routing::get, Router};
|
|
use std::net::SocketAddr;
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
// build our application with a route
|
|
let app = Router::new().route("/", get(handler));
|
|
|
|
// run it
|
|
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
|
|
println!("listening on {}", addr);
|
|
axum::Server::bind(&addr)
|
|
.serve(app.into_make_service())
|
|
.await
|
|
.unwrap();
|
|
}
|
|
|
|
async fn handler() -> Html<&'static str> {
|
|
Html("<h1>Hello, World!</h1>")
|
|
}
|