2021-07-09 21:36:14 +02:00
|
|
|
use axum::prelude::*;
|
2021-06-13 11:01:40 +02:00
|
|
|
use serde::Deserialize;
|
|
|
|
use std::net::SocketAddr;
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
|
|
|
// build our application with some routes
|
2021-06-19 14:06:49 +02:00
|
|
|
let app = route("/", get(show_form).post(accept_form));
|
2021-06-13 11:01:40 +02:00
|
|
|
|
|
|
|
// run it with hyper
|
|
|
|
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
|
|
|
|
tracing::debug!("listening on {}", addr);
|
2021-06-19 12:50:33 +02:00
|
|
|
hyper::Server::bind(&addr)
|
|
|
|
.serve(app.into_make_service())
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2021-06-13 11:01:40 +02:00
|
|
|
}
|
|
|
|
|
2021-06-19 12:50:33 +02:00
|
|
|
async fn show_form() -> response::Html<&'static str> {
|
2021-06-13 11:01:40 +02:00
|
|
|
response::Html(
|
|
|
|
r#"
|
|
|
|
<!doctype html>
|
|
|
|
<html>
|
|
|
|
<head></head>
|
|
|
|
<body>
|
|
|
|
<form action="/" method="post">
|
|
|
|
<label for="name">
|
|
|
|
Enter your name:
|
|
|
|
<input type="text" name="name">
|
|
|
|
</label>
|
|
|
|
|
|
|
|
<label>
|
|
|
|
Enter your email:
|
|
|
|
<input type="text" name="email">
|
|
|
|
</label>
|
|
|
|
|
|
|
|
<input type="submit" value="Subscribe!">
|
|
|
|
</form>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
|
|
struct Input {
|
|
|
|
name: String,
|
|
|
|
email: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn accept_form(extract::Form(input): extract::Form<Input>) {
|
|
|
|
dbg!(&input);
|
|
|
|
}
|