ayun_server/traits/
request.rs

1#[async_trait::async_trait]
2pub trait RequestTrait {
3    fn content_type(&self) -> mime::Mime;
4    fn header<K>(&self, key: K) -> Option<&str>
5    where
6        K: axum::http::header::AsHeaderName;
7    fn user_agent(&self) -> &str;
8
9    async fn path<T: serde::de::DeserializeOwned + Send + 'static>(
10        &mut self,
11    ) -> Result<T, axum::extract::rejection::PathRejection>;
12
13    #[cfg(feature = "request-query")]
14    async fn query<T: serde::de::DeserializeOwned + 'static>(
15        &mut self,
16    ) -> Result<T, axum::extract::rejection::QueryRejection>;
17
18    #[cfg(feature = "request-form")]
19    async fn form<T: serde::de::DeserializeOwned>(
20        self,
21    ) -> Result<T, axum::extract::rejection::FormRejection>;
22
23    #[cfg(feature = "request-json")]
24    async fn json<T: serde::de::DeserializeOwned>(
25        self,
26    ) -> Result<T, axum::extract::rejection::JsonRejection>;
27
28    #[cfg(feature = "request-multipart")]
29    async fn multipart<T: serde::de::DeserializeOwned>(self) -> crate::ServerResult<T>;
30
31    #[cfg(feature = "request-multipart")]
32    async fn file(self, key: &str) -> crate::ServerResult<Option<axum::body::Bytes>>;
33
34    #[cfg(feature = "request-validate")]
35    async fn validate<T: serde::de::DeserializeOwned + validator::Validate>(
36        self,
37    ) -> crate::ServerResult<T>;
38
39    #[cfg(feature = "request-id")]
40    fn id(&self) -> Option<&str>;
41
42    #[cfg(feature = "request-auth")]
43    fn user(&self) -> Option<ayun_auth::support::UserClaims>;
44
45    #[cfg(feature = "request-auth")]
46    fn token(&self) -> crate::ServerResult<String>;
47}