axum/examples/hello_world.rs
David Pedersen 5c12328892
Replace hyper::Server with axum::Server in docs (#118)
* Replace `hyper::Server` with `axum::Server` in docs

* Change readme as well
2021-08-04 15:38:51 +02:00

28 lines
605 B
Rust

//! Run with
//!
//! ```not_rust
//! cargo run --example hello_world
//! ```
use axum::prelude::*;
use std::net::SocketAddr;
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
// build our application with a route
let app = route("/", get(handler));
// run it
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
tracing::debug!("listening on {}", addr);
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
}
async fn handler() -> response::Html<&'static str> {
response::Html("<h1>Hello, World!</h1>")
}