aboutsummaryrefslogtreecommitdiff
path: root/examples/parameters.rs
blob: 153e64a4302d630a8096630c3b13c631cb5910f2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//! `cargo run --example parameters --features response-macros`

use windmark::success;

#[windmark::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
  windmark::router::Router::new()
    .set_private_key_file("windmark_private.pem")
    .set_certificate_file("windmark_public.pem")
    .mount(
      "/language/:language",
      success!(
        context,
        format!(
          "Your language of choice is {}.",
          context.parameters.get("language").unwrap()
        )
      ),
    )
    .mount(
      "/name/:first/:last",
      success!(
        context,
        format!(
          "Your name is {} {}.",
          context.parameters.get("first").unwrap(),
          context.parameters.get("last").unwrap()
        )
      ),
    )
    .run()
    .await
}