reqwest_mock-0.1.0 doesn't have any documentation.
reqwest_mock
Provides a mockable reqwest-like HTTP client.
Write your code generic over the Client trait,
and in production use DirectClient while in testing
you can use ReplayClient, which will record a request
the first time and replay it every time the exact same request is made in the
future.
Examples
use reqwest_mock::{Client, DirectClient, ReplayClient, Error};
use reqwest_mock::header::UserAgent;
struct MyClient<C: Client> {
client: C,
}
fn new_client() -> MyClient<DirectClient> {
MyClient {
client: DirectClient::new()
}
}
#[cfg(test)]
fn test_client(path: &str) -> MyClient<ReplayClient> {
MyClient {
client: ReplayClient::new(path)
}
}
impl<C: Client> MyClient<C> {
pub fn get_time(&self) -> Result<String, Error> {
let response = self.client
.get("https://now.httpbin.org/")
.header(UserAgent("MyClient".to_string()))
.send()?;
response.body_to_utf8()
}
}