1
0
mirror of https://github.com/actix/actix-website synced 2025-02-02 12:19:04 +01:00

25 lines
524 B
Rust
Raw Normal View History

2019-06-17 14:34:23 -04:00
// <urlencoded>
2020-09-12 16:21:54 +01:00
use actix_web::{post, web, HttpResponse};
2019-06-26 01:27:17 -04:00
use serde::Deserialize;
2019-06-17 14:34:23 -04:00
2019-06-26 01:27:17 -04:00
#[derive(Deserialize)]
struct FormData {
username: String,
}
2019-06-17 14:34:23 -04:00
2020-09-12 16:21:54 +01:00
#[post("/")]
2019-12-29 02:32:47 +09:00
async fn index(form: web::Form<FormData>) -> HttpResponse {
2019-06-26 01:27:17 -04:00
HttpResponse::Ok().body(format!("username: {}", form.username))
}
2019-06-17 14:34:23 -04:00
// </urlencoded>
2019-06-26 01:27:17 -04:00
2020-09-12 16:21:54 +01:00
#[actix_web::main]
2019-12-29 02:32:47 +09:00
async fn main() -> std::io::Result<()> {
2019-06-26 01:27:17 -04:00
use actix_web::{App, HttpServer};
2020-09-12 16:21:54 +01:00
HttpServer::new(|| App::new().service(index))
.bind("127.0.0.1:8080")?
2019-06-26 01:27:17 -04:00
.run()
2019-12-29 02:32:47 +09:00
.await
2019-06-26 01:27:17 -04:00
}