HTTP mocking library for Rust
Simple yet powerful HTTP mocking library for Rust
Website
·
API Reference
·
Crate
·
Chat on Discord
·
Report Bug
·
Request Feature
·
Support this ProjectAdd httpmock to Cargo.toml:
[dev-dependencies]
httpmock = "0.9.0"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 GET requests
to path /translate with query parameter word=hello. The corresponding HTTP response will contain the text body
hola.
When the specified expectations do not match the received request, mock.assert() fails the test with a detailed error description,
including a diff that shows the differences between the expected and actual HTTP requests. Example:
0 of 1 expected requests matched the mock specification.
Here is a comparison with the most similar unmatched request (request number 1):
------------------------------------------------------------
1 : Query Parameter Mismatch
------------------------------------------------------------
Expected:
key [equals] word
value [equals] hello-rustaceans
Received (most similar query parameter):
word=hello
All received query parameter values:
1. word=hello
Matcher: query_param
Docs: https://docs.rs/httpmock/0.9.0/httpmock/struct.When.html#method.query_paramSee the official website for detailed API documentation.
You can find examples in the
httpmock test directory.
The official website and reference docs also contain a lot of examples.
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.
No open issues yet, or sync has not completed.