✨ Nuevo ejemplo "/hello/{name}"
This commit is contained in:
parent
7ffea7fab6
commit
2f4184fe26
5 changed files with 46 additions and 5 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
"hello-world",
|
"hello-world",
|
||||||
|
"hello-name",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
9
examples/hello-name/Cargo.toml
Normal file
9
examples/hello-name/Cargo.toml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
[package]
|
||||||
|
name = "hello_name"
|
||||||
|
version = "0.0.0"
|
||||||
|
edition = "2021"
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
actix-web = "4"
|
||||||
|
pagetop = { version = "0.0", path = "../../pagetop" }
|
||||||
31
examples/hello-name/src/main.rs
Normal file
31
examples/hello-name/src/main.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
use pagetop::prelude::*;
|
||||||
|
|
||||||
|
define_handle!(APP_HELLO_NAME);
|
||||||
|
|
||||||
|
struct HelloName;
|
||||||
|
|
||||||
|
impl ModuleTrait for HelloName {
|
||||||
|
fn handle(&self) -> Handle {
|
||||||
|
APP_HELLO_NAME
|
||||||
|
}
|
||||||
|
|
||||||
|
fn configure_service(&self, cfg: &mut service::web::ServiceConfig) {
|
||||||
|
cfg.service(hello_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[service::get("/hello/{name}")]
|
||||||
|
async fn hello_name(
|
||||||
|
request: service::HttpRequest,
|
||||||
|
path: service::web::Path<String>,
|
||||||
|
) -> ResultPage<Markup, FatalError> {
|
||||||
|
let name = path.into_inner();
|
||||||
|
Page::new(request)
|
||||||
|
.with_in("content", Html::with(html! { h1 { "Hello " (name) "!" } }))
|
||||||
|
.render()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_web::main]
|
||||||
|
async fn main() -> std::io::Result<()> {
|
||||||
|
Application::prepare(&HelloName).unwrap().run()?.await
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "example_hello_world"
|
name = "hello_world"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
|
||||||
|
|
@ -9,14 +9,14 @@ impl ModuleTrait for HelloWorld {
|
||||||
APP_HELLO_WORLD
|
APP_HELLO_WORLD
|
||||||
}
|
}
|
||||||
|
|
||||||
fn configure_service(&self, cfg: &mut server::web::ServiceConfig) {
|
fn configure_service(&self, cfg: &mut service::web::ServiceConfig) {
|
||||||
cfg.route("/", server::web::get().to(hello_world));
|
cfg.route("/", service::web::get().to(hello_world));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn hello_world(request: server::HttpRequest) -> ResultPage<Markup, FatalError> {
|
async fn hello_world(request: service::HttpRequest) -> ResultPage<Markup, FatalError> {
|
||||||
Page::new(request)
|
Page::new(request)
|
||||||
.with_in("content", L10n::html(html! { h1 { "Hello World!" } }))
|
.with_in("content", Html::with(html! { h1 { "Hello World!" } }))
|
||||||
.render()
|
.render()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue