mirror of
https://github.com/actix/actix-website
synced 2025-01-22 16:15:56 +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"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "1.0"
|
||||
actix-web = "2.0"
|
||||
actix-rt = "1.0"
|
||||
serde = "1.0"
|
||||
|
@ -8,25 +8,25 @@ struct Register {
|
||||
country: String,
|
||||
}
|
||||
|
||||
fn index() -> HttpResponse {
|
||||
async fn index() -> HttpResponse {
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/html; charset=utf-8")
|
||||
.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)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
#[actix_rt::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.route("/", web::get().to(index))
|
||||
.route("/register", web::post().to(register))
|
||||
})
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.bind("127.0.0.1:8088")?
|
||||
.run()
|
||||
.unwrap();
|
||||
.await
|
||||
}
|
||||
// </easy-form-handling>
|
||||
|
Loading…
x
Reference in New Issue
Block a user