mirror of
https://github.com/actix/actix-website
synced 2024-11-27 18:12:57 +01:00
Adds to workspace to test all code actually functions.
This commit is contained in:
parent
a5f7e0d095
commit
cbd27e7668
@ -1,6 +1,7 @@
|
||||
[workspace]
|
||||
members = [
|
||||
"application",
|
||||
"front-page",
|
||||
"getting-started",
|
||||
"server",
|
||||
"url-dispatch",
|
||||
|
8
examples/front-page/Cargo.toml
Normal file
8
examples/front-page/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
||||
[workspace]
|
||||
members = [
|
||||
"main-example",
|
||||
"flexible-responders",
|
||||
"easy-form-handling",
|
||||
"request-routing",
|
||||
"powerful-extractors",
|
||||
]
|
8
examples/front-page/easy-form-handling/Cargo.toml
Normal file
8
examples/front-page/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/front-page/easy-form-handling/src/main.rs
Normal file
35
examples/front-page/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() -> actix_web::Result<HttpResponse> {
|
||||
Ok(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:8000")
|
||||
.expect("Can not bind to port 8000")
|
||||
.run()
|
||||
.unwrap();
|
||||
}
|
||||
// </easy-form-handling>
|
30
examples/front-page/easy-form-handling/static/form.html
Normal file
30
examples/front-page/easy-form-handling/static/form.html
Normal file
@ -0,0 +1,30 @@
|
||||
<!doctype htmtl>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>Forms</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h3>Will hit handle_post_1</h3>
|
||||
|
||||
<form action=/register method=POST>
|
||||
|
||||
<label>
|
||||
Name:
|
||||
<input name="username">
|
||||
</label>
|
||||
|
||||
<label>
|
||||
Country:
|
||||
<input name="country">
|
||||
</label>
|
||||
|
||||
<button type=submit>Submit</button>
|
||||
|
||||
</form>
|
||||
|
||||
<hr>
|
||||
|
||||
</body>
|
||||
</html>
|
6
examples/front-page/flexible-responders/Cargo.toml
Normal file
6
examples/front-page/flexible-responders/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "flexible-responders"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
5
examples/front-page/flexible-responders/src/main.rs
Normal file
5
examples/front-page/flexible-responders/src/main.rs
Normal file
@ -0,0 +1,5 @@
|
||||
// <flexible-responders>
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
// </flexible-responders>
|
7
examples/front-page/main-example/Cargo.toml
Normal file
7
examples/front-page/main-example/Cargo.toml
Normal file
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "front-page"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "1.0"
|
20
examples/front-page/main-example/src/main.rs
Normal file
20
examples/front-page/main-example/src/main.rs
Normal file
@ -0,0 +1,20 @@
|
||||
// <main-example>
|
||||
use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer};
|
||||
|
||||
fn greet(req: HttpRequest) -> HttpResponse {
|
||||
let name = req.match_info().get("name").unwrap_or("World");
|
||||
HttpResponse::Ok().body(format!("Hello {}!", &name))
|
||||
}
|
||||
|
||||
fn main() {
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.service(web::resource("/").to(greet))
|
||||
.service(web::resource("/{name}").to(greet))
|
||||
})
|
||||
.bind("127.0.0.1:8000")
|
||||
.expect("Can not bind to port 8000")
|
||||
.run()
|
||||
.unwrap();
|
||||
}
|
||||
// </main-example>
|
7
examples/front-page/powerful-extractors/Cargo.toml
Normal file
7
examples/front-page/powerful-extractors/Cargo.toml
Normal file
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "powerful-extractors"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "1.0"
|
3
examples/front-page/powerful-extractors/src/main.rs
Normal file
3
examples/front-page/powerful-extractors/src/main.rs
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
7
examples/front-page/request-routing/Cargo.toml
Normal file
7
examples/front-page/request-routing/Cargo.toml
Normal file
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "request-routing"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "1.0"
|
23
examples/front-page/request-routing/src/main.rs
Normal file
23
examples/front-page/request-routing/src/main.rs
Normal file
@ -0,0 +1,23 @@
|
||||
// <request-routing>
|
||||
use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer};
|
||||
|
||||
fn index(_req: HttpRequest) -> HttpResponse {
|
||||
HttpResponse::Ok().body("Hello from the index page.")
|
||||
}
|
||||
|
||||
fn hello(path: web::Path<String>) -> HttpResponse {
|
||||
HttpResponse::Ok().body(format!("Hello {}!", &path))
|
||||
}
|
||||
|
||||
fn main() {
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.service(web::resource("/").to(index))
|
||||
.service(web::resource("/{name}").to(hello))
|
||||
})
|
||||
.bind("127.0.0.1:8000")
|
||||
.unwrap()
|
||||
.run()
|
||||
.unwrap();
|
||||
}
|
||||
// </request-routing>
|
Loading…
Reference in New Issue
Block a user