To use Maud with Axum, enable the axum feature in your Cargo.toml. This adds an implementation of IntoResponse for Markup and PreEscaped<String>, allowing them to be used directly as responses.
[dependencies]
maud = { version = "*", features = ["axum"] }
use maud::{html, Markup};
use axum::{Router, routing::get};
async fn hello_world() -> Markup {
html! {
h1 { "Hello, World!" }
}
}
#[tokio::main]
async fn main() {
// build our application with a single route
let app = Router::new().route("/", get(hello_world));
// run it with hyper on localhost:3000
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app.into_make_service()).await.unwrap();
}