Skip to content
Provides a mockable reqwest-like HTTP client for Rust.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

reqwest_mock Docs Build Status

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.


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()

fn test_client(path: &str) -> MyClient<ReplayClient> {
    MyClient {
        client: ReplayClient::new(path)

impl<C: Client> MyClient<C> {
    /// For simplicity's sake we are not parsing the response but just extracting the
    /// response body.
    /// Also in your own code it might be a good idea to define your own `Error` type.
    pub fn get_time(&self) -> Result<String, Error> {
        let response = self.client

You can’t perform that action at this time.