started howto module to provide basic examples and explore possibilities

This commit is contained in:
2023-10-04 00:46:44 +02:00
parent e78a06547a
commit f010ee0f47
7 changed files with 84 additions and 35 deletions

9
src/howto/mod.rs Normal file
View File

@@ -0,0 +1,9 @@
use axum::{routing::get, Router};
use crate::state::AppState;
pub mod views;
pub fn routes() -> Router<AppState> {
Router::new().route("/", get(views::howtos).post(views::answer_question))
}

17
src/howto/views.rs Normal file
View File

@@ -0,0 +1,17 @@
use axum::{extract::State, response::IntoResponse, Form};
use crate::service::templates;
use serde::Deserialize;
#[derive(Deserialize)]
pub struct Question {
question: String,
}
pub async fn howtos(templates: State<templates::Templates>) -> impl IntoResponse {
templates.render_html("howto/index.html", ())
}
pub async fn answer_question(Form(question): Form<Question>) -> impl IntoResponse {
"There is your answer!".to_owned()
}

View File

@@ -1,3 +1,4 @@
mod howto;
mod service;
mod state;
@@ -26,6 +27,7 @@ async fn main() {
let app = Router::new()
.route("/", get(home))
.route("/hello", get(hello_world))
.nest("/howto", howto::routes())
.route_service("/static/*file", handlers::static_handler.into_service())
.fallback(handlers::not_found_handler)
.with_state(state);