diff --git a/Cargo.toml b/Cargo.toml index a4443e2..e4538ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,5 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] +askama = "0.12.1" +askama_axum = "0.4.0" axum = "0.7.5" tokio = { version = "1.38.0", features = ["full"] } diff --git a/src/main.rs b/src/main.rs index 740b768..872e94e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,12 +2,23 @@ use axum::{ routing::get, Router, }; +use askama_axum::Template; + +#[derive(Template)] +#[template(path = "hello.html")] +struct HelloTemplate<'a> { + name: &'a str, +} #[tokio::main] async fn main() { let app = Router::new() - .route("/", get(|| async { "Hello, World!" })); + .route("/", get(hello_world)); let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); axum::serve(listener, app).await.unwrap(); } + +async fn hello_world() -> HelloTemplate<'static> { + HelloTemplate { name: "world" } +} diff --git a/templates/hello.html b/templates/hello.html new file mode 100644 index 0000000..8149be7 --- /dev/null +++ b/templates/hello.html @@ -0,0 +1 @@ +Hello, {{ name }}!