Skip to content

Commit 1b82db0

Browse files
committed
conduit-axum/examples: Use ConduitAxumHandler to implement route handlers
1 parent 6c250dd commit 1b82db0

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

conduit-axum/examples/server.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#![deny(clippy::all)]
22

3+
use axum::routing::get;
34
use conduit::{Body, Handler, RequestExt, ResponseResult};
4-
use conduit_axum::Server;
5+
use conduit_axum::{ConduitAxumHandler, Server};
56
use conduit_router::RouteBuilder;
67
use http::{header, Response};
78

@@ -12,14 +13,21 @@ use std::thread::sleep;
1213
async fn main() {
1314
tracing_subscriber::fmt::init();
1415

15-
let router = axum::Router::new();
16+
let router = axum::Router::new()
17+
.route("/axum/", get(wrap(endpoint)))
18+
.route("/axum/panic", get(wrap(panic)))
19+
.route("/axum/error", get(wrap(error)));
1620

1721
let app = build_conduit_handler();
1822
let addr = ([127, 0, 0, 1], 12345).into();
1923

2024
Server::serve(&addr, router, app).await;
2125
}
2226

27+
pub fn wrap<H>(handler: H) -> ConduitAxumHandler<H> {
28+
ConduitAxumHandler::wrap(handler)
29+
}
30+
2331
fn build_conduit_handler() -> impl Handler {
2432
let mut router = RouteBuilder::new();
2533
router.get("/", endpoint);

conduit-axum/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ mod tests;
5454
mod tokio_utils;
5555

5656
pub use error::ServiceError;
57-
pub use fallback::{conduit_into_axum, CauseField, ConduitFallback, ErrorField};
57+
pub use fallback::{
58+
conduit_into_axum, CauseField, ConduitAxumHandler, ConduitFallback, ErrorField,
59+
};
5860
pub use server::Server;
5961
pub use tokio_utils::spawn_blocking;
6062

0 commit comments

Comments
 (0)