//! Run with //! //! ```not_rust //! cargo run --example form //! ``` use axum::prelude::*; use serde::Deserialize; use std::net::SocketAddr; #[tokio::main] async fn main() { // Set the RUST_LOG, if it hasn't been explicitly defined if std::env::var("RUST_LOG").is_err() { std::env::set_var("RUST_LOG", "form=debug") } tracing_subscriber::fmt::init(); // build our application with some routes let app = 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() -> response::Html<&'static str> { response::Html( r#"
"#, ) } #[derive(Deserialize, Debug)] struct Input { name: String, email: String, } async fn accept_form(extract::Form(input): extract::Form) { dbg!(&input); }