[−][src]Struct reqwest_mock::client::StubClient
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]
fn execute(
&self,
config: Option<&ClientConfig>,
request: Request
) -> Result<Response, Error>
[src]
&self,
config: Option<&ClientConfig>,
request: Request
) -> Result<Response, Error>
fn config(&self) -> &ClientConfig
[src]
fn config_mut(&mut self) -> &mut ClientConfig
[src]
fn get<'cl, U: IntoUrl>(&'cl self, url: U) -> RequestBuilder<'cl, Self>
[src]
fn post<'cl, U: IntoUrl>(&'cl self, url: U) -> RequestBuilder<'cl, Self>
[src]
fn put<'cl, U: IntoUrl>(&'cl self, url: U) -> RequestBuilder<'cl, Self>
[src]
fn patch<'cl, U: IntoUrl>(&'cl self, url: U) -> RequestBuilder<'cl, Self>
[src]
fn delete<'cl, U: IntoUrl>(&'cl self, url: U) -> RequestBuilder<'cl, Self>
[src]
fn head<'cl, U: IntoUrl>(&'cl self, url: U) -> RequestBuilder<'cl, Self>
[src]
fn request<'cl, U: IntoUrl>(
&'cl self,
method: Method,
url: U
) -> RequestBuilder<'cl, Self>
[src]
&'cl self,
method: Method,
url: U
) -> RequestBuilder<'cl, Self>
impl From<StubClient> for GenericClient
[src]
fn from(c: StubClient) -> Self
[src]
Auto Trait Implementations
impl RefUnwindSafe for StubClient
impl Send for StubClient
impl Sync for StubClient
impl Unpin for StubClient
impl UnwindSafe for StubClient
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,