started howto module to provide basic examples and explore possibilities
This commit is contained in:
9
src/howto/mod.rs
Normal file
9
src/howto/mod.rs
Normal 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
17
src/howto/views.rs
Normal 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()
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user