1
0
mirror of https://github.com/actix/actix-website synced 2025-01-23 00:25:55 +01:00

Update easu-form-handling example

This commit is contained in:
Yuki Okushi 2019-12-29 01:24:52 +09:00
parent 1e5f5ecf8b
commit 66c3bd8729
2 changed files with 8 additions and 7 deletions

View File

@ -4,5 +4,6 @@ version = "1.0.0"
edition = "2018" edition = "2018"
[dependencies] [dependencies]
actix-web = "1.0" actix-web = "2.0"
actix-rt = "1.0"
serde = "1.0" serde = "1.0"

View File

@ -8,25 +8,25 @@ struct Register {
country: String, country: String,
} }
fn index() -> HttpResponse { async fn index() -> HttpResponse {
HttpResponse::Ok() HttpResponse::Ok()
.content_type("text/html; charset=utf-8") .content_type("text/html; charset=utf-8")
.body(include_str!("../static/form.html")) .body(include_str!("../static/form.html"))
} }
fn register(form: web::Form<Register>) -> impl Responder { async fn register(form: web::Form<Register>) -> impl Responder {
format!("Hello {} from {}!", form.username, form.country) format!("Hello {} from {}!", form.username, form.country)
} }
fn main() { #[actix_rt::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| { HttpServer::new(|| {
App::new() App::new()
.route("/", web::get().to(index)) .route("/", web::get().to(index))
.route("/register", web::post().to(register)) .route("/register", web::post().to(register))
}) })
.bind("127.0.0.1:8088") .bind("127.0.0.1:8088")?
.unwrap()
.run() .run()
.unwrap(); .await
} }
// </easy-form-handling> // </easy-form-handling>