[][src]Struct reqwest_mock::client::StubClient

pub struct StubClient { /* fields omitted */ }

A client which allows you to stub out the response to a request explicitly.

Examples

use reqwest_mock::{Client, Method, StubClient, StubDefault, StubSettings, StubStrictness, Url};

let mut client = StubClient::new(StubSettings {
    // If a request without a corresponding stub is made we want an error
    // to be returned when our code executes the request.
    default: StubDefault::Error,

    // We want the `StubClient` to compare actual requests and provided
    // mocks by their method and their url.
    strictness: StubStrictness::MethodUrl,
});

// Mock a request.
client
    .stub(Url::parse("http://example.com/mocking").unwrap())
        .method(Method::GET)
    .response()
        .body("Mocking is fun!")
        .mock();

let response = client.get("http://example.com/mocking").send().unwrap();
assert_eq!(response.body_to_utf8().unwrap(), "Mocking is fun!".to_string());

Implementations

impl StubClient[src]

pub fn new(stub_settings: StubSettings) -> Self[src]

Create a new instance of StubClient.

Please consult StubSettings for more information about the possible settings.

pub fn stub<'cl>(&'cl mut self, url: Url) -> RequestStubber<'cl>[src]

Provide a stub for a request to the provided url.

This will return a RequestStubber, which in a first step will allow you to specify the full details of the request. Make sure that they match the StubStrictness provided in the settings.

After you are finished specifying the details of the matching request, call response() to return a ResponseStubber instance and start specifying the response. Finally use ResponseStubber::mock() to register the mock into the client.

Trait Implementations

impl Client for StubClient[src]

impl From<StubClient> for GenericClient[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,