WireMock Hosting¶
This guide provides step-by-step instructions for configuring Wiremock hosting in your Aspire AppHost using Wiremock CLI. This will allow you to automatically pull down Wiremock cloud project stubs and run a mock server locally using the CLI.
📚 Useful Resources¶
📋 Prerequisites¶
Before you begin, ensure you have:
- ✅ Wiremock CLI installed (
npm install -g @wiremock/cli) - ✅ .NET 10.0 SDK installed
- ✅ An API project with 1 or more external API dependencies you wish to mock
- ✅ Wiremock Cloud project(s) with mocks defined (optional, for auto-update feature)
📁 Projects¶
- AppHost Project: Contains logic for setting up your application and dependencies
🛠️ WiremockCli - Aspire Hosting Extensions¶
Overview¶
The WiremockCli namespace provides Aspire hosting extensions for integrating WireMock CLI into your distributed applications. This enables you to mock external API dependencies during local development, with optional integration to WireMock Cloud for managing mock definitions.
Features¶
- 🎯 Service Discovery Integration - Mock resources integrate with Aspire's service discovery
- 🔄 WireMock Cloud Integration - Automatically pull mock definitions from WireMock Cloud projects and enable auto-updates
- 📦 Multiple Mock Services - Configure multiple mock services with different ports and project IDs
- 📊 Dashboard Integration - View mock service status in the Aspire dashboard
Usage Example¶
// Create the WireMock CLI resource
var wiremock = builder
.AddWiremockCli("wiremock");
// Add a mock service that pulls definitions from WireMock Cloud
var mockApi = wiremock.AddMock(
name: "external-api",
port: 8080,
wiremockProjectId: "abc123xyz", // Get this from your WireMock Cloud mock URL
autoUpdate: true
);
// Wire your application to reference the mock service
builder
.AddProject<Projects.MyApiService>("my-api-service")
.WithReference(mockApi)
.WaitFor(mockApi);
Finding Your WireMock Project ID¶
- Navigate to your mock in WireMock Cloud
- Copy the URL from your browser:
https://app.wiremock.cloud/mock-apis/abc123xyz/stubs/... - The
wiremockProjectIdis the unique identifier in the URL (in this example:abc123xyz)
Default Directory¶
WireMock CLI files are stored in ./.wiremock by default. The directory is created automatically if it doesn't exist.
Feedback¶
Please provide feedback on these APIs through:
- 🐛 Issues for bugs or problems
- 💡 Feature requests for improvements
- 📝 Discussions for general feedback