1use crate::{Context, Response};
2use hyper::StatusCode;
3use serde::Deserialize;
4
5pub async fn test_handler(ctx: Context) -> String {
6 format!("test called, state_thing was: {}", ctx.state.state_thing)
7}
8
9#[derive(Deserialize)]
10struct SendRequest {
11 name: String,
12 active: bool,
13}
14
15pub async fn send_handler(mut ctx: Context) -> Response {
16 let body: SendRequest = match ctx.body_json().await {
17 Ok(v) => v,
18 Err(e) => {
19 return hyper::Response::builder()
20 .status(StatusCode::BAD_REQUEST)
21 .body(format!("could not parse JSON: {}", e).into())
22 .unwrap()
23 }
24 };
25
26 Response::new(
27 format!(
28 "send called with name: {} and active: {}",
29 body.name, body.active
30 )
31 .into(),
32 )
33}
34
35pub async fn param_handler(ctx: Context) -> String {
36 let param = match ctx.params.find("some_param") {
37 Some(v) => v,
38 None => "empty",
39 };
40 format!("param called, param was: {}", param)
41}