1
0
mirror of https://github.com/actix/actix-website synced 2025-07-02 09:34:33 +02:00
Files
actix-website/examples/requests/src/urlencoded.rs
2022-02-26 03:56:24 +00:00

25 lines
527 B
Rust

// <urlencoded>
use actix_web::{post, web, HttpResponse};
use serde::Deserialize;
#[derive(Deserialize)]
struct FormData {
username: String,
}
#[post("/")]
async fn index(form: web::Form<FormData>) -> HttpResponse {
HttpResponse::Ok().body(format!("username: {}", form.username))
}
// </urlencoded>
#[actix_web::main]
async fn main() -> std::io::Result<()> {
use actix_web::{App, HttpServer};
HttpServer::new(|| App::new().service(index))
.bind(("127.0.0.1", 8080))?
.run()
.await
}