Files
axum/examples/customize-extractor-error/src/main.rs
T
2023-03-10 12:02:11 +01:00

39 lines
1.1 KiB
Rust

//! Run with
//!
//! ```not_rust
//! cargo run -p example-customize-extractor-error
//! ```
mod custom_extractor;
mod derive_from_request;
mod with_rejection;
use axum::{routing::post, Router};
use std::net::SocketAddr;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
#[tokio::main]
async fn main() {
tracing_subscriber::registry()
.with(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| "example_customize_extractor_error=trace".into()),
)
.with(tracing_subscriber::fmt::layer())
.init();
// Build our application with some routes
let app = Router::new()
.route("/with-rejection", post(with_rejection::handler))
.route("/custom-extractor", post(custom_extractor::handler))
.route("/derive-from-request", post(derive_from_request::handler));
// Run our application
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();
}