Skip to main content

WhyhttpResponse

Struct WhyhttpResponse 

Source
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

Source

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);
Source

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

pub fn header<K: Into<String>, V: Into<String>>(self, key: K, value: V) -> Self

Adds a response header.

let server = whyhttp::Whyhttp::run();
server.when().path("/data").response()
    .header("content-type", "application/json");
Source

pub fn body<S: Into<String>>(self, body: S) -> Self

Sets the response body.

let server = whyhttp::Whyhttp::run();
server.when().path("/hello").response().body("world");
Source§

impl WhyhttpResponse

Source

pub fn addr(&self) -> SocketAddr

Returns the server’s socket address.

Source

pub fn url(&self) -> String

Returns the server’s base URL (e.g. http://127.0.0.1:PORT).

Source§

impl WhyhttpResponse

Source

pub fn when_path<S: Into<String>>(&self, path: S) -> WhenWhyhttpRequest

Shorthand for self.when().path(path).

Source

pub fn when_method<S: Into<String>>(&self, method: S) -> WhenWhyhttpRequest

Shorthand for self.when().method(method).

Source

pub fn when_query<K: Into<String>, V: Into<String>>( &self, key: K, value: V, ) -> WhenWhyhttpRequest

Shorthand for self.when().query(key, value).

Source

pub fn when_query_exists<K: Into<String>>(&self, key: K) -> WhenWhyhttpRequest

Shorthand for self.when().query_exists(key).

Source

pub fn when_without_query<K: Into<String>>(&self, key: K) -> WhenWhyhttpRequest

Shorthand for self.when().without_query(key).

Source

pub fn when_header<K: Into<String>, V: Into<String>>( &self, key: K, value: V, ) -> WhenWhyhttpRequest

Shorthand for self.when().header(key, value).

Source

pub fn when_header_exists<K: Into<String>>(&self, key: K) -> WhenWhyhttpRequest

Shorthand for self.when().header_exists(key).

Source

pub fn when_without_header<K: Into<String>>(&self, key: K) -> WhenWhyhttpRequest

Shorthand for self.when().without_header(key).

Source

pub fn when_body<S: Into<String>>(&self, body: S) -> WhenWhyhttpRequest

Shorthand for self.when().body(body).

Source

pub fn when_without_body(&self) -> WhenWhyhttpRequest

Shorthand for self.when().without_body().

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.