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:
parent
1e5f5ecf8b
commit
66c3bd8729
@ -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"
|
||||||
|
@ -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>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user