pub struct HttpRequest {
pub method: Option<String>,
pub path: Option<String>,
pub query_string_parameters: Option<HashMap<String, Vec<String>>>,
pub headers: Option<HashMap<String, Vec<String>>>,
pub body: Option<Body>,
pub socket_address: Option<SocketAddress>,
}Expand description
Matcher for an HTTP request. Uses builder methods for fluent construction.
§Example
use mockserver_client::HttpRequest;
let request = HttpRequest::new()
.method("POST")
.path("/api/users")
.header("Content-Type", "application/json")
.query_param("page", "1")
.body("{}");Fields§
§method: Option<String>§path: Option<String>§query_string_parameters: Option<HashMap<String, Vec<String>>>§headers: Option<HashMap<String, Vec<String>>>§body: Option<Body>§socket_address: Option<SocketAddress>Implementations§
Source§impl HttpRequest
impl HttpRequest
Sourcepub fn socket_address(self, socket_address: SocketAddress) -> Self
pub fn socket_address(self, socket_address: SocketAddress) -> Self
Set the downstream socket address to connect to.
Used by load-scenario steps (and forwarded/proxied requests) to direct
the rendered request at a specific host/port/scheme rather than relying
on the request’s Host header.
Sourcepub fn query_param(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn query_param( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Add a query string parameter (multiple values per key supported).
Sourcepub fn header(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn header(self, key: impl Into<String>, value: impl Into<String>) -> Self
Add a header (multiple values per key supported).
Sourcepub fn file_body(self, file_path: impl Into<String>) -> Self
pub fn file_body(self, file_path: impl Into<String>) -> Self
Set a file body (type “FILE”) with optional content type and template type.
Use Body::file for richer construction if you need content type or
template type set.
Sourcepub fn body_value(self, body: Body) -> Self
pub fn body_value(self, body: Body) -> Self
Set a pre-built Body value (use with Body::file for FILE bodies).
Trait Implementations§
Source§impl Clone for HttpRequest
impl Clone for HttpRequest
Source§fn clone(&self) -> HttpRequest
fn clone(&self) -> HttpRequest
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for HttpRequest
impl Debug for HttpRequest
Source§impl Default for HttpRequest
impl Default for HttpRequest
Source§fn default() -> HttpRequest
fn default() -> HttpRequest
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for HttpRequest
impl<'de> Deserialize<'de> for HttpRequest
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for HttpRequest
impl PartialEq for HttpRequest
Source§fn eq(&self, other: &HttpRequest) -> bool
fn eq(&self, other: &HttpRequest) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl Serialize for HttpRequest
impl Serialize for HttpRequest
impl StructuralPartialEq for HttpRequest
Auto Trait Implementations§
impl Freeze for HttpRequest
impl RefUnwindSafe for HttpRequest
impl Send for HttpRequest
impl Sync for HttpRequest
impl Unpin for HttpRequest
impl UnsafeUnpin for HttpRequest
impl UnwindSafe for HttpRequest
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