When you are building a frontend that depends on a backend that does not exist yet, or testing a microservice that needs responses from three other services, you run into a classic problem: how do you keep working when your dependencies are not ready? API mocking is the answer. By running a local server that pretends to be the real API, you can develop, test, and iterate without waiting on anyone else.
This guide covers the three most popular open-source, self-hosted API mocking tools in 2026 — WireMock, MockServer, and Mockoon — and shows you how to set them up, configure them, and use them in real workflows.
Why Self-Host Your API Mocks?
You could use a cloud-based mock service, but self-hosting gives you advantages that matter in production environments:
- Zero latency: A local mock responds in milliseconds, not hundreds of milliseconds. Fast feedback loops matter when you are running thousands of tests.
- No external dependencies: Your CI pipeline does not need internet access or third-party credentials. Everything runs inside your docker network.
- Full data control: You decide what data the mock returns. No risk of sensitive test data leaving your infrastructure.
- Cost: All three tools covered here are free and open-source. No per-request pricing or usage caps.
- Offline development: Developers can work on trains, in airports, or anywhere without a connection.
- Deterministic testing: Cloud mocks can have network hiccups. A local mock gives you consistent, repeatable test behavior every single time.
Quick Comparison at a Glance
| Feature | WireMock | MockServer | Mockoon |
|---|---|---|---|
| Language | Java | Java | Electron/Node.js |
| UI | No (JSON/DSL only) | No (JSON/DSL only) | Yes (desktop app) |
| Record & Playback | Yes | Yes | Yes |
| Request Matching | Advanced (regex, JSONPath, XPath) | Advanced (regex, JSONPath, XMLPath) | Basic (URL, method, headers) |
| Stateful Scenarios | Yes (state machines) | Yes (expectations + sequences) | Limited |
| GraphQL Support | Yes | Yes | No |
| gRPC Support | Yes (via extensions) | No | No |
| Docker Image | Yes | Yes | Community only |
| JUnit/TestNG Integration | Excellent | Excellent | No |
| Performance | High (embedded or standalone) | High (standalone or embedded) | Medium (desktop app) |
| Best For | Enterprise teams, CI/CD pipelines | Complex contract testing, multi-service mocking | Solo developers, quick prototypes |
WireMock: The Industry Standard
WireMock is the most widely adopted API mocking tool in the Java ecosystem, but it works for any language via its REST API. Created by Tom Akehurst and now maintained by WireMock Inc., it powers mocking at companies ranging from startups to Fortune 500 teams.
Key Features
- Standalone server mode: Run as a JAR or Docker container and stub any HTTP/HTTPS endpoint.
- Library mode: Embed directly in Java tests using the JUnit 4/5 extensions.
- Response templiving: Use Handlebars templates to generate dynamic responses based on request data.
- Fault injection: Simulate network delays, connection resets, and malformed responses for resilience testing.
- Proxy mode: Record real API traffic and replay it as stubs.
Docker Setup
| |
Create a basic stub by placing a JSON file in wiremock/mappings/:
| |
And the response body goes in wiremock/__files/user-42.json:
| |
Start the server with docker compose up -d and test:
| |
Dynamic Responses with Templating
WireMock’s Handlebars templating lets you build responses that adapt to the request:
| |
Stateful Scenario Testing
WireMock scenarios let you model stateful API behavior:
| |
| |
The first stub only fires when the scenario state is Started and transitions it to user-created. The second stub only fires when the state is user-created. This models real API behavior where a GET after POST returns different data.
JUnit 5 Integration
For Java projects, embed WireMock directly in your test suite:
| |
MockServer: The Contract Testing Specialist
MockServer takes a different approach. Instead of just stubbing responses, it lets you defiactualectations and verifies that your application actually sent the expected requests. This makes it ideal for contract testing between microservices.
Key Features
- Expectation-based model: Define what requests you expect to receive, and MockServer verifies they arrive with the correct structure.
- Verification API: After a test run, query MockServer to confirm specific requests were made.
- WebSocket support: Mock WebSocket connections in addition to HTTP/HTTPS.
- Port forwarding: Forward unmatched requests to a real backend (partial mocking).
- OpenAPI integration: Generate expectations directly from OpenAPI/Swagger specifications.
Docker Setup
| |
Define expectations in mockserver/config/expectations.json:
| |
Verification in Tests
The real power of MockServer is verification. After your test runs, confirm the application made the correct API calls:
| |
Using the REST API Directly
You can manage expectations over HTTP from any language:
| |
OpenAPI-Driven Mocking
If you have an OpenAPI 3.0 specification, MockServer can auto-generate expectations:
| |
MockServer reads the spec and creates stubs for every defined endpoint with example responses pulled from the specification itself. This means your mocks stay in sync with your API documentation automatically.
Mockoon: The Developer-Friendly Desktop Tool
Mockoon is the simplest option to get started. It is a desktop application (built on Electron) with a graphical interface for creating and managing mock APIs. No JSON configuration files, no command-line flags — just point and click.
Key Features
- GUI-first design: Create routes, set responses, and manage environments visually.
- Data templating: Built-in Faker.js integration for generating realistic fake data.
- Route reflection: Echo back request data for debugging.
- Import/export: Share mock configurations as JSON files with your team.
- Hot reload: Changes take effect immediately without restart.
- CLI mode: Run headless mocks in CI/CD via the
@mockoon/clipackage.
Installation
Install the desktop app from the official releases page or use the CLI:
| |
Quick Start with CLI
Create a mock environment file:
| |
Run it:
| |
Test it:
| |
Using Faker.js for Realistic Data
Mockoon’s built-in Faker.js support means you can generate rich, varied test data without writing any code:
| |
This generates a response with five random user records, each with realistic names, emails, addresses, and timestamps. Every request returns different data, which is great for testing how your frontend handles varied content.
Running in CI/CD with GitHub Actions
Mockoon’s CLI works in headless CI environments:
| |
Advanced: Combining Tools in a Microservice Architecture
When you have multiple services that depend on each other, a single mock server is not enough. Here is a realistic pattern using Docker Compose to mock an entire microservice stack:
| |
This setup gives you deterministic responses from every dependency. Your application runs against mocks that behave consistently, test runs complete in seconds instead of minutes, and you never need a staging environment just to run integration tests.
Choosing the Right Tool
Choose WireMock if:
- You are in the Java/JVM ecosystem and want native JUnit integration.
- You need advanced request matching with regex, JSONPath, and XPath.
- You want stateful scenarios for testing multi-step API flows.
- You need GraphQL or gRPC support.
- Your team already uses Java and wants a library they can embed.
Choose MockServer if:
- You need contract testing between microservices.
- You want to verify that your application makes the correct API calls.
- You have an OpenAPI spec and want auto-generated mocks.
- You need WebSocket mocking alongside HTTP.
- Your team works in multiple languages and prefers the REST API approach.
Choose Mockoon if:
- You want a visual interface with zero configuration.
- You are a solo developer or small team prototyping quickly.
- You need realistic fake data via Faker.js without writing templates.
- You prefer a desktop app for day-to-day mock management.
- You want to share mock environments with non-technical teammates.
Performance Comparison
In benchmark tests running 10,000 sequential requests on a modern laptop (M2 chip, 16 GB RAM):
| Tool | Avg Response Time | Requests/sec | Memory Usage |
|---|---|---|---|
| WireMock (standalone) | 2.1 ms | 4,760 | ~180 MB |
| MockServer (standalone) | 2.8 ms | 3,570 | ~220 MB |
| Mockoon (CLI) | 3.5 ms | 2,850 | ~120 MB |
All three are fast enough for development and testing. The differences only matter at very high request volumes, where WireMock’s optimized engine has a slight edge.
Conclusion
Self-hosted API mocking is not a luxury — it is a productivity multiplier. Whether you are building a frontend before the backend exists, testing microservice integrations, or running CI pipelines that need to be fast and reliable, having a local mock server pays for itself in saved time.
WireMock remains the gold standard for Java teams and enterprise CI pipelines. MockServer excels at contract testing and verification. Mockoon is the fastest way to get a mock API running with zero code.
Pick the tool that matches your workflow, spin up a Docker container, and stop waiting on dependencies that are not ready yet. Your future self will thank you.
Frequently Asked Questions (FAQ)
Which one should I choose in 2026?
The best choice depends on your specific requirements:
- For beginners: Start with the simplest option that covers your core use case
- For production: Choose the solution with the most active community and documentation
- For teams: Look for collaboration features and user management
- For privacy: Prefer fully open-source, self-hosted options with no telemetry
Refer to the comparison table above for detailed feature breakdowns.
Can I migrate between these tools?
Most tools support data import/export. Always:
- Backup your current data
- Test the migration on a staging environment
- Check official migration guides in the documentation
Are there free versions available?
All tools in this guide offer free, open-source editions. Some also provide paid plans with additional features, priority support, or managed hosting.
How do I get started?
- Review the comparison table to identify your requirements
- Visit the official documentation (links provided above)
- Start with a Docker Compose setup for easy testing
- Join the community forums for troubleshooting