-
Hi, I'm trying to make a GET handler that use query strings.
#[derive(Serialize, Deserialize, Debug)]
pub struct GetQuery {
train_id: Option<String>,
departure: Option<String>,
} with this struct, in a GET handler I have to check whether GetQuery is partially filled or not ( #[derive(Serialize, Deserialize, Debug)]
pub struct GetQuery {
data: Option<Data>
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Data {
train_id: String,
departure: String
} then this raises a question. query string only allows primitive key-value data. how actix_web will treat this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
although it doesn't directly answer the question, I found that nested struct can be flattened using |
Beta Was this translation helpful? Give feedback.
-
For an all-or-nothing approach, you can use an Option extractor. #[derive(Serialize, Deserialize, Debug)]
pub struct Data {
train_id: String,
departure: String
}
async fn handler(query: Option<web::Query<Data>>) { ... } |
Beta Was this translation helpful? Give feedback.
For an all-or-nothing approach, you can use an Option extractor.