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

27 lines
598 B
Rust
Raw Normal View History

//! Run with
//!
//! ```not_rust
2022-04-29 18:53:41 +02:00
//! cd examples && cargo run -p example-hello-world
//! ```
2021-11-02 13:07:34 +01:00
use axum::{response::Html, routing::get, Router};
use std::net::SocketAddr;
#[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 addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
}
2021-11-02 13:07:34 +01:00
async fn handler() -> Html<&'static str> {
Html("<h1>Hello, World!</h1>")
}