Features
- 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.
- Debugging support.
- Network delay simulation.
- Standalone mode with an accompanying Docker image.
- Support for Regex matching, JSON, serde, cookies, and more.
Getting Started
Add httpmock
to Cargo.toml
:
[]
= "0.5.5"
You can then use httpmock
as follows:
use MockServer;
use GET;
// Start a lightweight mock server.
let server = start;
// Create a mock on the server.
let hello_mock = server.mock;
// Send an HTTP request to the mock server. This simulates your code.
let response = get.unwrap;
// Ensure the specified mock was called exactly one time (or fail with a detailed error description).
hello_mock.assert;
// Ensure the mock server did respond as specified.
assert_eq!;
The above example will spin up a lightweight HTTP mock server and configure it to respond to all GET
requests
to path /translate
with query parameter word=hello
. The corresponding HTTP response will contain the text body
Привет
.
Usage
See the reference docs for detailed API documentation.
Examples
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.
License
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.