HTTP mocking library for Rust.
Documentation · Crate · Report Bug · Request Feature · Changelog
- Simple, expressive, fluent API.
- Many built-in helpers for easy request matching.
- Parallel test execution.
- Extensible request matching.
- Fully asynchronous core with synchronous and asynchronous APIs.
- Advanced verification and debugging support.
- Network delay simulation.
- Support for Regex matching, JSON, serde, cookies, and more.
- Standalone mode with an accompanying Docker image.
- Support for mock specification based on YAML files.
You can then use
httpmock as follows:
The above example will spin up a lightweight HTTP mock server and configure it to respond to all
/translate with query parameter
word=hello. The corresponding HTTP response will contain the text body
See the reference docs for detailed API documentation.
You can find examples in the
httpmock test directory.
The reference docs also contain a lot of examples. There is an online tutorial as well.
Standalone Mock Server
You can use
httpmock to run a standalone mock server that is executed in a separate process. There is a
Docker image available at Dockerhub to get started quickly.
The standalone mode allows you to mock HTTP based APIs for many API clients, not only the ones
inside your Rust tests, but also completely different programs running on remote hosts.
This is especially useful if you want to use
httpmock in system or end-to-end tests that require mocked services
(such as REST APIs, data stores, authentication providers, etc.).
Please refer to the docs for more information
File Based Mock Specification
For convenience, the standalone mode also allows you to use YAML files for mock specification, so you do not need to
use Rust or any other programming language at all. The mock specification file schema is very similar to the
Rust API, so it's easy to jump between the two. Please find an example mock specification file
Please refer to the docs for more information.
httpmock is free software: you can redistribute it and/or modify it under the terms of the MIT Public License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MIT Public License for more details.