Open LuckyQinLin opened 1 year ago
This is a query parameter in poem_openapi
.
Documentation: https://docs.rs/poem-openapi/latest/poem_openapi/param/struct.Query.html
Example:
use poem_openapi::param::Path;
use poem_openapi::param::Query;
use poem_openapi::payload::Json;
use poem_openapi::ApiResponse;
use poem_openapi::Enum;
use poem_openapi::Object;
use poem_openapi::OpenApi;
#[OpenApi]
impl ProductApi {
/// Documentation comment
///
/// Document stuff here ...
#[oai(path = "/products", method = "get")]
pub(crate) async fn get_products(
&self,
offset: Query<Option<u32>>,
limit: Query<Option<u32>>,
name: Query<Option<String>>,
state_filter: Query<Option<ProductState>>,
) -> poem::Result<GetProductResponses> {
let offset = offset.0.unwrap_or_default();
let limit = limit.0.unwrap_or(10);
let name = name.0.unwrap_or_default();
let state_filter = state_filter.0.unwrap_or_default();
todo!("Response etc...")
}
}
/// Enum to filter products by theyr synced-state.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Enum)]
#[oai(rename_all = "camelCase")]
pub(crate) enum ProductState {
/// Does not filter by product state.
DoNotCare,
/// Get only synced products.
Synced,
/// Get only unsynced products.
Unsynced,
}
Note that this is not a minimal example. I just slapped all inports from my real source-file in here.
http://127.0.0.1:3000/api?id=6
How does this URL get the request parameters?