I am building a little webapp in Actix-web, but I can't find any example of getting parameters out of a POST request in Actix-web anywhere.
Searching their excellent examples repo only gives a couple of (to me) meaningful examples, but they both deal with JSON and not form data.
I also found this page, which I suspect holds the answer; but to a beginner this isn't much help.
I imagine it should look something like:
<form method="POST">
<input type="password" name="password">
<button type="submit">Login</button>
</form>
and
fn main() {
// ...
App::with_state(AppState { db: pool.clone() })
.middleware(IdentityService::new(
CookieIdentityPolicy::new(&[0; 32])
.name("auth-cookie")
.secure(true),
))
.resource("/login", |r| {
r.method(http::Method::GET).with(login);
r.method(http::Method::POST).with(perform_login) // help!
})
}
struct LoginParams {
password: String,
}
fn perform_login(mut req: HttpRequest<AppState>, params: LoginParams) -> HttpResponse {
if params.password == "abc123" {
req.remember("logged-in".to_owned());
// redirect to home
};
// show "wrong password" error
}