poem_queryext/
lib.rs

1#![doc = include_str!("../README.md")]
2#![forbid(unsafe_code)]
3#![warn(clippy::dbg_macro, clippy::use_debug)]
4#![warn(missing_docs, missing_debug_implementations)]
5#![cfg_attr(docsrs, feature(doc_auto_cfg))]
6
7//! Implement poem FromRequest to deserialize struct from query string.
8//!
9//! #### Example
10//! ```no_run
11//! use poem_queryext::QueryExt;
12//! use poem_openapi::{payload::PlainText, OpenApi};
13//! use serde::Deserialize;
14//!
15//! struct Api;
16//!
17//! #[OpenApi]
18//! impl Api {
19//!   //test url: /test?name=cx  
20//!   //test url: /test?name=cx&age=18&hobby[0]=music&hobby[1]=game  
21//!   #[oai(path = "/test", method = "get")]
22//!   async fn test(&self, query: QueryExt<'_, QueryObj>) -> PlainText<String> {
23//!        let obj = query.0;
24//!        PlainText(format!(
25//!            "name:{},age:{},hobby:{}",
26//!            obj.name,
27//!            obj.age.unwrap_or_default(),
28//!            obj.hobby.unwrap_or_default().join(",")
29//!        ))
30//!    }
31//! }
32//!
33//! #[derive(Deserialize)]
34//! #[serde(rename_all = "camelCase")]
35//! struct QueryObj{
36//!     name:String,
37//!     age:Option<i8>,//Non mandatory fields  use Option<T>
38//!     hobby:Option<Vec<String>>//Non mandatory fields  use Option<T>
39//! }
40//!
41//! ```
42mod query_ext;
43
44pub use query_ext::QueryExt;