//! Run with //! //! ```not_rust //! cargo run -p example-print-request-response //! ``` use axum::{ body::{Body, Bytes}, http::{Request, StatusCode}, response::{IntoResponse, Response}, routing::post, Router, }; use axum_extra::middleware::{self, Next}; use std::net::SocketAddr; #[tokio::main] async fn main() { // Set the RUST_LOG, if it hasn't been explicitly defined if std::env::var_os("RUST_LOG").is_none() { std::env::set_var( "RUST_LOG", "example_print_request_response=debug,tower_http=debug", ) } tracing_subscriber::fmt::init(); let app = Router::new() .route("/", post(|| async move { "Hello from `POST /`" })) .layer(middleware::from_fn(print_request_response)); 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 print_request_response( req: Request
, next: Next, ) -> Result