//! Run with //! //! ```not_rust //! cd examples && cargo run -p example-form //! ``` use axum::{extract::Form, response::Html, routing::get, Router}; use serde::Deserialize; use std::net::SocketAddr; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[tokio::main] async fn main() { tracing_subscriber::registry() .with(tracing_subscriber::EnvFilter::new( std::env::var("RUST_LOG").unwrap_or_else(|_| "example_form=debug".into()), )) .with(tracing_subscriber::fmt::layer()) .init(); // build our application with some routes let app = Router::new().route("/", get(show_form).post(accept_form)); // run it with hyper 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 show_form() -> Html<&'static str> { Html( r#"
"#, ) } #[derive(Deserialize, Debug)] #[allow(dead_code)] struct Input { name: String, email: String, } async fn accept_form(Form(input): Form) { dbg!(&input); }