pub struct CallQuery { /* private fields */ }Expand description
A collection of query parameters for HTTP requests with OpenAPI 3.1 support.
CallQuery provides a type-safe way to build and serialize query parameters
for HTTP requests. It supports different parameter styles as defined by the
OpenAPI 3.1 specification and automatically generates OpenAPI parameter schemas.
§Examples
§Basic Usage
use clawspec_core::{CallQuery, ParamValue, ParamStyle};
let query = CallQuery::new()
.add_param("search", ParamValue::new("hello world"))
.add_param("limit", ParamValue::new(10))
.add_param("active", ParamValue::new(true));
// This would generate: ?search=hello+world&limit=10&active=true§Array Parameters with Different Styles
use clawspec_core::{CallQuery, ParamValue, ParamStyle};
let query = CallQuery::new()
// Form style (default): ?tags=rust&tags=web&tags=api
.add_param("tags", ParamValue::new(vec!["rust", "web", "api"]))
// Space delimited: ?categories=tech%20programming
.add_param("categories", ParamValue::with_style(
vec!["tech", "programming"],
ParamStyle::SpaceDelimited
))
// Pipe delimited: ?ids=1|2|3
.add_param("ids", ParamValue::with_style(
vec![1, 2, 3],
ParamStyle::PipeDelimited
));§Type Safety
The query system is type-safe and will prevent invalid parameter types:
- Objects are not supported as query parameters (will return an error)
- All parameters must implement
SerializeandToSchematraits - Parameters are automatically converted to appropriate string representations
Implementations§
Source§impl CallQuery
impl CallQuery
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new empty query parameter collection.
§Examples
use clawspec_core::CallQuery;
let query = CallQuery::new();
// Query is initially emptySourcepub fn add_param<T: ParameterValue>(
self,
name: impl Into<String>,
param: impl Into<ParamValue<T>>,
) -> Self
pub fn add_param<T: ParameterValue>( self, name: impl Into<String>, param: impl Into<ParamValue<T>>, ) -> Self
Adds a query parameter with the given name and value using the builder pattern.
This method consumes self and returns a new CallQuery with the parameter added,
allowing for method chaining. The parameter must implement both Serialize and
ToSchema traits for proper serialization and OpenAPI schema generation.
§Parameters
name: The parameter name (will be converted toString)param: The parameter value that can be converted intoParamValue<T>
§Examples
use clawspec_core::{CallQuery, ParamValue, ParamStyle};
// Ergonomic usage - pass values directly
let query = CallQuery::new()
.add_param("search", "hello")
.add_param("limit", 10)
.add_param("active", true);
// Explicit ParamValue usage for custom styles
let query = CallQuery::new()
.add_param("tags", ParamValue::with_style(
vec!["rust", "web"],
ParamStyle::SpaceDelimited
));Trait Implementations§
Auto Trait Implementations§
impl Freeze for CallQuery
impl RefUnwindSafe for CallQuery
impl Send for CallQuery
impl Sync for CallQuery
impl Unpin for CallQuery
impl UnwindSafe for CallQuery
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more