Actix-web: Print Request Information

How do I write a rule that applies to all routes that prints out certain things?

Currently, I have about 20 different routes that do all of this:

#[post("/login")]
async fn login(body: String) -> HttpResponse {
    println!("{}",format!("____________________________").black().on_white());
    println!("{}",format!("post -> /login").cyan());
    println!("{}",body);
    resp!("OK")
}

What I want to do is define something that has the 3 printlns in it and have all the routes print that information in that structure.

Would I do this in a macro?

You should use a middleware for that.

1 Like

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.