Registry / testing / httpmock

httpmock

JSON →
library0.8.3rscratesunverified

HTTP mocking library for Rust that allows you to simulate HTTP servers and test HTTP clients.

# Cargo.toml [dependencies] httpmock = "0.8.3"
INSTALL
IMPORT
SIG · HTTPMOCK
H
httpmock
testingrustv0.8.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MockServer
use httpmock::MockServer;

Creates a mock HTTP server, defines a mock endpoint, and asserts the request was made.

use httpmock::MockServer; let server = MockServer::start(); let mock = server.mock(|when, then| { when.method("GET").path("/hello"); then.status(200).body("world"); }); let response = reqwest::get(&server.url("/hello")).unwrap(); assert_eq!(response.text().unwrap(), "world"); mock.assert();
Debug
Known issues
gotchaMockServer runs on a random port; ensure your client uses the correct URL from server.url()
fix
Always use server.url() or server.base_url() to construct request URLs.
affects: >=0.6.0
Upgrade
Version history
0.8.3latest on crates.io
Audit
Dependencies

No dependency data recorded yet.

Agent activity
17 hits · last 30 days
node
16
OpenAI (training)
1
Resources
httpmock — cargo add httpmock · libregistry