mirror of
https://github.com/actix/actix-website
synced 2025-06-27 07:29:02 +02:00
Cargo can't do nested workspaces.
This commit is contained in:
8
examples/easy-form-handling/Cargo.toml
Normal file
8
examples/easy-form-handling/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "easy-form-handling"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "1.0"
|
||||
serde = "1.0"
|
35
examples/easy-form-handling/src/main.rs
Normal file
35
examples/easy-form-handling/src/main.rs
Normal file
@ -0,0 +1,35 @@
|
||||
// <easy-form-handling>
|
||||
use actix_web::{web, App, HttpResponse, HttpServer};
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Register {
|
||||
username: String,
|
||||
country: String,
|
||||
}
|
||||
|
||||
fn index() -> HttpResponse {
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/html; charset=utf-8")
|
||||
.body(include_str!("../static/form.html"))
|
||||
}
|
||||
|
||||
fn register(params: web::Form<Register>) -> actix_web::Result<HttpResponse> {
|
||||
Ok(HttpResponse::Ok().body(format!(
|
||||
"Hello {} from {}!",
|
||||
params.username, params.country
|
||||
)))
|
||||
}
|
||||
|
||||
fn main() {
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.route("/", web::get().to(index))
|
||||
.route("/register", web::post().to(register))
|
||||
})
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.run()
|
||||
.unwrap();
|
||||
}
|
||||
// </easy-form-handling>
|
28
examples/easy-form-handling/static/form.html
Normal file
28
examples/easy-form-handling/static/form.html
Normal file
@ -0,0 +1,28 @@
|
||||
<!doctype htmtl>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>Forms</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h3>Its a form.</h3>
|
||||
|
||||
<form action=/register method=POST>
|
||||
|
||||
<label>
|
||||
Name:
|
||||
<input name="username">
|
||||
</label>
|
||||
|
||||
<label>
|
||||
Country:
|
||||
<input name="country">
|
||||
</label>
|
||||
|
||||
<button type=submit>Submit</button>
|
||||
|
||||
</form>
|
||||
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user