diff --git a/api/Cargo.toml b/api/Cargo.toml index 6b8150bc19..0b85e27b0f 100644 --- a/api/Cargo.toml +++ b/api/Cargo.toml @@ -11,13 +11,14 @@ keywords = ["trillium", "framework", "async"] categories = ["web-programming::http-server", "web-programming"] [features] -default = ["forms"] +default = ["forms", "querystrong"] forms = ["serde_urlencoded", "form_urlencoded"] [dependencies] form_urlencoded = { version = "1.2.0", optional = true } log = "0.4.19" mime = "0.3.17" +querystrong = { version = "0.3.0", optional = true } serde = { version = "1.0.181", features = ["derive"] } serde_json = "1.0.104" serde_path_to_error = "0.1.14" diff --git a/api/src/from_conn.rs b/api/src/from_conn.rs index 7744fb0a76..194e3c5309 100644 --- a/api/src/from_conn.rs +++ b/api/src/from_conn.rs @@ -1,3 +1,4 @@ +use crate::ApiConnExt; use trillium::{async_trait, Conn}; /// A trait to extract content from [`Conn`]s to be used as the second @@ -37,6 +38,22 @@ impl FromConn for Option { } } +#[async_trait] +impl FromConn for serde_json::Value { + async fn from_conn(conn: &mut Conn) -> Option { + let res = conn.deserialize_json::().await; + conn.store_error(res) + } +} + +#[cfg(feature = "querystrong")] +#[async_trait] +impl FromConn for querystrong::QueryStrong { + async fn from_conn(conn: &mut Conn) -> Option { + Some(conn.querystring().parse().unwrap_or_default()) + } +} + macro_rules! impl_from_conn_tuple { ($($name:ident)+) => ( #[async_trait]