Files
axum/examples/customize-extractor-error/src/main.rs
T
Altair BuenoandDavid Pedersen 789f51ba1a Extend custom rejection examples (#1276)
* examples: Created new `error-handling` example

* examples(error-handling): Add error codes and responses

* examples(error-handling): `custom_extractor`

* examples(error-handling): `derive_from_request`

* examples(error-handling): Using POST instead of GET

* examples(error-handling): Using `thiserror` for `derive_from_request`

* examples(error-handling): Using `snake-case` for routes

* revert(error-handling): Use `From` impl instead of `thiserror`

refs: 3533d96215

* examples(error-handling): Removed chrono

* examples: merged `error-handling` and `customize-extractor-error`

* examples(customize-extractor-error): Improved error codes

* examples(customize-extractor-error): rustfmt

* examples(customize-extractor-error): Removed `matched-path` feature

Co-authored-by: David Pedersen <[email protected]>

* examples(customize-extractor-error): added `publish=false` to `Cargo.toml`

Co-authored-by: David Pedersen <[email protected]>

* examples(customize-extractor-error): Fix env filter

* examples(customize-extractor-error): Added README

* examples(customize-extractor-error): Added `with_rejection` comments

* examples(customize-extractor-error): Added `custom_extractor` comments

* examples(customize-extractor-error):Typo on `with_rejection`

* examples(customize-extractor-error): Added `boilerplate` con to `custom_extractor`

* examples(customize-extractor-error): Added `derive_from_request` comments

* examples(customize-extractor-error): typo impossible

* examples(customize-extractor-error): typos

* examples(customize-extractor-error): replaced `extensions` with `extract`

* examples(customize-extractor-error): typo `from`

Co-authored-by: David Pedersen <[email protected]>

Co-authored-by: David Pedersen <[email protected]>
2022-08-19 13:11:03 +00:00

39 lines
1.1 KiB
Rust

//! Run with
//!
//! ```not_rust
//! cd examples && 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::new(
std::env::var("RUST_LOG")
.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();
}