soph_server/traits/
request.rs

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