A ResponseTemplate acts as a blueprint for the response a MockServer will return. It encapsulates the status code, headers, body, MIME type, and an optional delay.
When a Mock is mounted to a MockServer using .respond_with(template), the server uses this blueprint to construct a full HTTP response whenever the request matches the mock's criteria. The template uses a builder-like pattern, allowing you to chain configuration methods (like insert_header or set_body_json) before passing it to the mock.
use wiremock::{MockServer, Mock, ResponseTemplate};
use wiremock::matchers::method;
// 1. Create the template (the blueprint)
let template = ResponseTemplate::new(200)
.insert_header("Content-Type", "application/json")
.set_body_json(vec![1, 2, 3]);
// 2. Attach the template to a Mock
Mock::given(method("GET"))
.respond_with(template)
.mount(&mock_server)
.await;