Axum and Tower-HTTP middleware issues

I'm having issues setting up middleware for my Axum server, my toml file includes the full features for both Tower and Tower-HTTP, but this code doesn't work:

use axum::{
use tower::ServiceBuilder;
use tower_http::{trace::TraceLayer};
// -- snip --
let app = Router::new()
        .route("/test/hello", get(routes::hello))
        .route("/test/cocktail", post(routes::cocktail))

I have more services commented out, and have tried just removing ServiceBuilder but all of them have an error along the lines of:

the trait Service<axum::http::Request<_>> is not implemented for Trace<Route<_>, SharedClassifier<ServerErrorsAsFailures>>

I thought my code was similar to what was shown on Axum's middleware docs page, what am I doing wrong?
Also, since I'm not very knowledgeable on middleware, what should I add? Cors, Validate Request Header, anything else?

I am at the same problem, and you probably want to consider staying at tower 0.4.4, as the 0.5.0 was just released yesterday.

1 Like

Tower Http has been upgraded for version 1 of http and http-body. Axum is in the process of migrating its versions over, should be done by 0.7

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.