I am writing an example for a template system (neutralts) in axum, the thing is that I have never used axum and I get a lot of errors when I try to read get parameters and cookies. the example is simply this:
async fn home_handler() -> Response<String> {
..
}
async fn handle_404() -> Response<String> {
...
}
#[tokio::main]
async fn main() {
let app = Router::new()
.route("/", get(home_handler))
.fallback(handle_404);
let addr = ([127, 0, 0, 1], 9090).into();
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
}
Can someone help me to make home_handler able to read cookies and get variables? I could use a link with examples about this.
jofas
January 22, 2025, 9:12am
2
There is the tower-cookies
crate which you can use to do cookie management in axum. It has examples .
1 Like
To clarify, every time I add parameters to home_handler, I get this error:
the trait bound `fn({type error}) -> impl Future<Output = &'static str> {handler}: Handler<_, _>` is not satisfied
--> src/main.rs:8:25
|
8 | .route("/", get(home_handler))
| --- ^^^^^^^ the trait `Handler<_, _>` is not implemented for fn item `fn({type error}) -> impl Future<Output = &'static str> {handler}`
| |
| required by a bound introduced by this call
jofas
January 22, 2025, 9:29am
4
The parameters of your handler must be extractors . I suspect {type error}
doesn't implement FromRequest
or FromRequestParts
, so it doesn't qualify as extractor.
I think I'm going to give up because I have a lot of web fw to do examples and it's consuming me a lot of time this one, I appreciate the answers, anyway if anyone can help me with this I'll be grateful here are the examples:
Web Template System
Thanks
system
Closed
April 22, 2025, 9:44am
6
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.