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#![allow(deprecated)]
7
8//! Implement poem FromRequest to deserialize struct from query string.
9//!
10//! #### Example
11//! ```no_run
12//! use poem_queryext::QueryExtN;
13//! use poem_openapi::{payload::PlainText, OpenApi};
14//! use serde::Deserialize;
15//!
16//! struct Api;
17//!
18//! #[OpenApi]
19//! impl Api {
20//! //test url: /test?name=cx
21//! //test url: /test?name=cx&age=18&hobby[0]=music&hobby[1]=game
22//! #[oai(path = "/test", method = "get")]
23//! async fn test(&self, QueryExtN(query): QueryExtN<QueryObj>) -> PlainText<String> {
24//! PlainText(format!(
25//! "name:{},age:{},hobby:{}",
26//! query.name,
27//! query.age.unwrap_or_default(),
28//! query.hobby.unwrap_or_default().join(",")
29//! ))
30//! }
31//! }
32//!
33//! #[derive(Deserialize)]
34//! #[serde(rename_all = "camelCase")]
35//! struct QueryObj{
36//! name:String,//if want use &str,use Arc<str> or Cow<'_,str>
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;
45pub use query_ext::QueryExtN;