pub struct WhyhttpResponse { /* private fields */ }Expand description
Builder for configuring the mock response.
Obtained from WhenWhyhttpRequest::response or
ShouldWhyhttpRequest::response. Chain status,
header, and body to
build the response returned when this expectation is matched.
Calling when starts a new expectation,
which is useful for registering multiple mocks in one chain.
Implementations§
Source§impl WhyhttpResponse
impl WhyhttpResponse
Sourcepub fn when(&self) -> WhenWhyhttpRequest
pub fn when(&self) -> WhenWhyhttpRequest
Creates a new expectation and enters the routing phase.
Use this to register multiple expectations in a single chain.
let server = whyhttp::Whyhttp::run();
server
.when().path("/a").response().status(200)
.when().path("/b").response().status(201);Sourcepub fn status(self, status: u16) -> Self
pub fn status(self, status: u16) -> Self
Sets the response status code. Defaults to 200.
let server = whyhttp::Whyhttp::run();
server.when().path("/created").response().status(201);Source§impl WhyhttpResponse
impl WhyhttpResponse
Sourcepub fn when_path<S: Into<String>>(&self, path: S) -> WhenWhyhttpRequest
pub fn when_path<S: Into<String>>(&self, path: S) -> WhenWhyhttpRequest
Shorthand for self.when().path(path).
Sourcepub fn when_method<S: Into<String>>(&self, method: S) -> WhenWhyhttpRequest
pub fn when_method<S: Into<String>>(&self, method: S) -> WhenWhyhttpRequest
Shorthand for self.when().method(method).
Sourcepub fn when_query<K: Into<String>, V: Into<String>>(
&self,
key: K,
value: V,
) -> WhenWhyhttpRequest
pub fn when_query<K: Into<String>, V: Into<String>>( &self, key: K, value: V, ) -> WhenWhyhttpRequest
Shorthand for self.when().query(key, value).
Sourcepub fn when_query_exists<K: Into<String>>(&self, key: K) -> WhenWhyhttpRequest
pub fn when_query_exists<K: Into<String>>(&self, key: K) -> WhenWhyhttpRequest
Shorthand for self.when().query_exists(key).
Sourcepub fn when_without_query<K: Into<String>>(&self, key: K) -> WhenWhyhttpRequest
pub fn when_without_query<K: Into<String>>(&self, key: K) -> WhenWhyhttpRequest
Shorthand for self.when().without_query(key).
Sourcepub fn when_header<K: Into<String>, V: Into<String>>(
&self,
key: K,
value: V,
) -> WhenWhyhttpRequest
pub fn when_header<K: Into<String>, V: Into<String>>( &self, key: K, value: V, ) -> WhenWhyhttpRequest
Shorthand for self.when().header(key, value).
Sourcepub fn when_header_exists<K: Into<String>>(&self, key: K) -> WhenWhyhttpRequest
pub fn when_header_exists<K: Into<String>>(&self, key: K) -> WhenWhyhttpRequest
Shorthand for self.when().header_exists(key).
Sourcepub fn when_without_header<K: Into<String>>(&self, key: K) -> WhenWhyhttpRequest
pub fn when_without_header<K: Into<String>>(&self, key: K) -> WhenWhyhttpRequest
Shorthand for self.when().without_header(key).
Sourcepub fn when_body<S: Into<String>>(&self, body: S) -> WhenWhyhttpRequest
pub fn when_body<S: Into<String>>(&self, body: S) -> WhenWhyhttpRequest
Shorthand for self.when().body(body).
Sourcepub fn when_without_body(&self) -> WhenWhyhttpRequest
pub fn when_without_body(&self) -> WhenWhyhttpRequest
Shorthand for self.when().without_body().