{"id":13478690,"url":"https://github.com/LukeMathWalker/wiremock-rs","last_synced_at":"2025-03-27T08:30:52.022Z","repository":{"id":38020102,"uuid":"255043026","full_name":"LukeMathWalker/wiremock-rs","owner":"LukeMathWalker","description":" HTTP mocking to test Rust applications. ","archived":false,"fork":false,"pushed_at":"2025-03-01T17:30:32.000Z","size":367,"stargazers_count":691,"open_issues_count":28,"forks_count":74,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-20T10:07:08.428Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LukeMathWalker.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-12T08:50:26.000Z","updated_at":"2025-03-19T09:08:43.000Z","dependencies_parsed_at":"2023-11-29T09:29:22.090Z","dependency_job_id":"cb6e9217-1618-4374-adbb-75a5ac5e4229","html_url":"https://github.com/LukeMathWalker/wiremock-rs","commit_stats":{"total_commits":188,"total_committers":39,"mean_commits":4.82051282051282,"dds":0.7180851063829787,"last_synced_commit":"4c79601e9c34b0b2ee48f269a5528235d2db9655"},"previous_names":[],"tags_count":44,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LukeMathWalker%2Fwiremock-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LukeMathWalker%2Fwiremock-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LukeMathWalker%2Fwiremock-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LukeMathWalker%2Fwiremock-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LukeMathWalker","download_url":"https://codeload.github.com/LukeMathWalker/wiremock-rs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245809656,"owners_count":20676028,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T16:02:00.888Z","updated_at":"2025-03-27T08:30:51.701Z","avatar_url":"https://github.com/LukeMathWalker.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":["Rust libraries"],"readme":"\u003ch1 align=\"center\"\u003ewiremock\u003c/h1\u003e\n\u003cdiv align=\"center\"\u003e\n \u003cstrong\u003e\n   HTTP mocking to test Rust applications.\n \u003c/strong\u003e\n\u003c/div\u003e\n\n\u003cbr /\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003c!-- Crates version --\u003e\n  \u003ca href=\"https://crates.io/crates/wiremock\"\u003e\n    \u003cimg src=\"https://img.shields.io/crates/v/wiremock.svg?style=flat-square\"\n    alt=\"Crates.io version\" /\u003e\n  \u003c/a\u003e\n  \u003c!-- Downloads --\u003e\n  \u003ca href=\"https://crates.io/crates/wiremock\"\u003e\n    \u003cimg src=\"https://img.shields.io/crates/d/wiremock.svg?style=flat-square\"\n      alt=\"Download\" /\u003e\n  \u003c/a\u003e\n  \u003c!-- docs.rs docs --\u003e\n  \u003ca href=\"https://docs.rs/wiremock\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square\"\n      alt=\"docs.rs docs\" /\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\u003cbr/\u003e\n\n`wiremock` provides HTTP mocking to perform black-box testing of Rust applications that\ninteract with third-party APIs.\n\nIt provides mocking of HTTP responses using request matching and response templating.\n\n*The name `wiremock` is a reference to [`WireMock.Net`](https://github.com/WireMock-Net/WireMock.Net), a .NET port of the original [`Wiremock`](http://wiremock.org/) from Java.*\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca style=\"display: inline\" href=\"https://docs.rs/wiremock\"\u003eDocumentation\u003c/a\u003e\n  \u003cspan style=\"display: inline\"\u003e - \u003c/span\u003e\n  \u003ca style=\"display: inline\" href=\"https://crates.io/crates/wiremock\"\u003eCrates.io\u003c/a\u003e\n\u003c/div\u003e\n\n# Table of Contents\n0. [How to install](#how-to-install)\n1. [Getting started](#getting-started)\n2. [Matchers](#matchers)\n3. [Spying](#spying)\n4. [Responses](#spying)\n5. [Test isolation](#test-isolation)\n6. [Runtime compatibility](#runtime-compatibility)\n7. [Efficiency](#efficiency)\n8. [Prior art](#prior-art)\n9. [Future evolution](#future-evolution)\n10. [Related projects](#related-projects)\n11. [License](#license)\n\n## How to install\n\nAdd `wiremock` to your development dependencies by editing the `Cargo.toml` file:\n```toml\n[dev-dependencies]\n# ...\nwiremock = \"0.6\"\n```\nOr by running:\n```bash\ncargo add wiremock --dev\n```\n\n## Getting started\n```rust\nuse wiremock::{MockServer, Mock, ResponseTemplate};\nuse wiremock::matchers::{method, path};\n\n#[async_std::main]\nasync fn main() {\n    // Start a background HTTP server on a random local port\n    let mock_server = MockServer::start().await;\n\n    // Arrange the behaviour of the MockServer adding a Mock:\n    // when it receives a GET request on '/hello' it will respond with a 200.\n    Mock::given(method(\"GET\"))\n        .and(path(\"/hello\"))\n        .respond_with(ResponseTemplate::new(200))\n        // Mounting the mock on the mock server - it's now effective!\n        .mount(\u0026mock_server)\n        .await;\n\n    // If we probe the MockServer using any HTTP client it behaves as expected.\n    let status = surf::get(format!(\"{}/hello\", \u0026mock_server.uri()))\n        .await\n        .unwrap()\n        .status();\n    assert_eq!(status.as_u16(), 200);\n\n    // If the request doesn't match any `Mock` mounted on our `MockServer` a 404 is returned.\n    let status = surf::get(format!(\"{}/missing\", \u0026mock_server.uri()))\n        .await\n        .unwrap()\n        .status();\n    assert_eq!(status.as_u16(), 404);\n}\n```\n\n## Matchers\n\n`wiremock` provides a set of matching strategies out of the box - check the [`matchers`] module\nfor a complete list.\n\nYou can define your own matchers using the [`Match`] trait, as well as using `Fn` closures.\nCheck [`Match`]'s documentation for more details and examples.\n\n## Spying\n\n`wiremock` empowers you to set expectations on the number of invocations to your [`Mock`]s -\ncheck the [`expect`] method for more details.\n\nExpectations can be used to verify that a side-effect has (or has not) taken place!\n\nExpectations are automatically verified during the shutdown of each [`MockServer`] instance,\nat the end of your test. A failed verification will trigger a panic.\nBy default, no expectations are set on your [`Mock`]s.\n\n## Responses\n\n`wiremock` lets you specify pre-determined responses using [`ResponseTemplate`] and\n[`respond_with`].\n\nYou are also given the option to have [`Mock`]s return different responses based on the matched\n[`Request`] using the [`Respond`] trait.\nCheck [`Respond`]'s documentation for more details and examples.\n\n## Test isolation\n\nEach instance of [`MockServer`] is fully isolated: [`start`] takes care of finding a random port\navailable on your local machine which is assigned to the new [`MockServer`].\n\nTo ensure full isolation and no cross-test interference, [`MockServer`]s shouldn't be\nshared between tests. Instead, [`MockServer`]s should be created in the test where they are used.\n\nWhen a [`MockServer`] instance goes out of scope (e.g. the test finishes), the corresponding\nHTTP server running in the background is shut down to free up the port it was using.\n\n## Runtime compatibility\n\n`wiremock` can be used (and it is tested to work) with both [`async_std`] and [`tokio`] as\nfutures runtimes.\nIf you encounter any compatibility bug, please open an issue on our [GitHub repository].\n\n## Efficiency\n\n`wiremock` maintains a pool of mock servers in the background to minimise the number of\nconnections and the time spent starting up a new [`MockServer`].\nPooling reduces the likelihood of you having to tune your OS configurations (e.g. ulimit).\n\nThe pool is designed to be invisible: it makes your life easier and your tests faster. If you\nend up having to worry about it, it's a bug: open an issue!\n\n## Prior art\n\n[`mockito`] and [`httpmock`] provide HTTP mocking for Rust.\n\nCheck the table below to see how `wiremock` compares to them across the following dimensions:\n- Test execution strategy (do tests have to be executed sequentially or can they be executed in parallel?);\n- How many APIs can I mock in a test?\n- Out-of-the-box request matchers;\n- Extensible request matching (i.e. you can define your own matchers);\n- Sync/Async API;\n- Spying (e.g. verify that a mock has/hasn't been called in a test);\n- Standalone mode (i.e. can I launch an HTTP mock server outside of a test suite?).\n\n|           | Test execution strategy | How many APIs can I mock? | Out-of-the-box request matchers | Extensible request matching | API        | Spying | Standalone mode |\n|-----------|-------------------------|---------------------------|---------------------------------|-----------------------------|------------|--------|-----------------|\n| mockito   | ✔ Parallel              | ✔ Unbounded               | ✔                               | ❌                          | Async/Sync | ✔      | ❌              |\n| httpmock  | ✔ Parallel              | ✔ Unbounded               | ✔                               | ✔                           | Async/Sync | ✔      | ✔               |\n| wiremock  | ✔ Parallel ️             | ✔ Unbounded               | ✔                               | ✔                           | Async      | ✔      | ❌              |\n\n\n## Future evolution\n\nMore request matchers can be added to those provided out-of-the-box to handle common usecases.\n\n## Related projects\n\n* [`stubr`](https://github.com/beltram/stubr) for mounting [`Wiremock`](http://wiremock.org/) json stubs in a [`MockServer`]. Also works as a cli.\n\n## License\n\nLicensed under either of Apache License, Version 2.0 or MIT license at your option.\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n\n[`MockServer`]: https://docs.rs/wiremock/latest/wiremock/struct.MockServer.html\n[`Mock`]: https://docs.rs/wiremock/latest/wiremock/struct.Mock.html\n[`ResponseTemplate`]: https://docs.rs/wiremock/latest/wiremock/struct.ResponseTemplate.html\n[`Request`]: https://docs.rs/wiremock/latest/wiremock/struct.Request.html\n[`Match`]: https://docs.rs/wiremock/latest/wiremock/trait.Match.html\n[`Respond`]: https://docs.rs/wiremock/latest/wiremock/trait.Respond.html\n[`start`]: https://docs.rs/wiremock/latest/wiremock/struct.MockServer.html#method.start\n[`expect`]: https://docs.rs/wiremock/latest/wiremock/struct.Mock.html#method.expect\n[`respond_with`]: https://docs.rs/wiremock/latest/wiremock/struct.MockBuilder.html#method.respond_with\n[`matchers`]: https://docs.rs/wiremock/latest/wiremock/matchers/index.html\n[GitHub repository]: https://github.com/LukeMathWalker/wiremock-rs\n[`mockito`]: https://docs.rs/mockito/\n[`httpmock`]: https://docs.rs/httpmock/\n[`async_std`]: https://docs.rs/async-std/\n[`tokio`]: https://docs.rs/tokio/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLukeMathWalker%2Fwiremock-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLukeMathWalker%2Fwiremock-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLukeMathWalker%2Fwiremock-rs/lists"}