Registry / testing / httptest

httptest

JSON →
library0.16.4rscratesunverified

HTTP testing facilities including a mock server for integration tests.

# Cargo.toml [dependencies] httptest = "0.16.4"
INSTALL
IMPORT
SIG · HTTPTEST
H
httptest
testingrustv0.16.4
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.

Server
use httptest::Server;

Sets up a mock HTTP server and tests a request.

use httptest::{Server, Expectation, matchers::*, responders::*}; fn main() { let server = Server::run(); server.expect( Expectation::matching(request::method_path("GET", "/hello")) .respond_with(status_code(200).body("world")), ); let response = reqwest::blocking::get(server.url("/hello")).unwrap(); assert_eq!(response.text().unwrap(), "world"); }
Debug
Known issues
gotchaThe server runs on a random port; ensure no firewall blocks it.
fix
Use server.url() to get the correct URL.
affects: >=0.1.0
Upgrade
Version history
0.16.4latest on crates.io
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
httptest — cargo add httptest · libregistry