rsiot/components/cmp_http_server/routes/
get.rs1use axum::extract;
2use axum::http::Uri;
3use axum::http::{header, HeaderMap};
4
5use crate::message::*;
6
7use super::super::shared_state::SharedState;
8
9pub async fn get<TMsg>(
11 uri: Uri,
12 extract::State(shared_state): extract::State<SharedState<TMsg>>,
13) -> (HeaderMap, Result<Vec<u8>, super::Error>)
14where
15 TMsg: MsgDataBound,
16{
17 let path = uri.path();
18
19 let mut headers = HeaderMap::new();
20 headers.insert(
21 header::CONTENT_TYPE,
22 "text/plain; charset=utf-8".parse().unwrap(),
23 );
24
25 let data = {
26 let get_endpoints = shared_state.get_endpoints.lock().await;
27 get_endpoints.handler(path, super::Error::UnknownPath, super::Error::Serde)
28 };
29
30 (headers, data)
31}