mockserver
MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby. MockServer also includes a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding).
Top Related Projects
A tool for mocking HTTP services
Industry standard API mocking for JavaScript.
Get a full fake REST API with zero coding in less than 30 seconds (seriously)
HTTP Request & Response Service, written in Python + Flask.
Quick Overview
MockServer is a versatile tool for mocking HTTP services. It allows developers to easily mock any server or service via HTTP or HTTPS, enabling them to decouple development and testing from external dependencies. MockServer can be used for both mocking and proxying, making it a powerful solution for various testing scenarios.
Pros
- Supports multiple interfaces: HTTP, HTTPS, SOCKS, and web sockets
- Flexible request matching and response generation
- Can be run as a standalone process, embedded in unit tests, or deployed in a container
- Extensive documentation and active community support
Cons
- Learning curve for advanced features and configurations
- Performance may be impacted when handling a large number of concurrent requests
- Some users report occasional stability issues in complex setups
- Limited built-in support for non-HTTP protocols
Code Examples
- Creating a simple expectation:
new MockServerClient("localhost", 1080)
.when(
request()
.withMethod("GET")
.withPath("/hello")
)
.respond(
response()
.withStatusCode(200)
.withBody("Hello, World!")
);
- Verifying a request:
new MockServerClient("localhost", 1080)
.verify(
request()
.withMethod("POST")
.withPath("/api/data")
.withBody("{\"key\": \"value\"}")
);
- Setting up a proxy:
new MockServerClient("localhost", 1080)
.forward(
request()
.withPath("/api/.*"),
forward()
.withHost("api.example.com")
);
Getting Started
- Add MockServer dependency to your project:
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-netty</artifactId>
<version>5.14.0</version>
</dependency>
- Start MockServer in your test:
MockServer mockServer = ClientAndServer.startClientAndServer(1080);
// Your test code here
mockServer.stop();
- Create expectations and verify requests as shown in the code examples above.
For more detailed instructions and advanced usage, refer to the official MockServer documentation.
Competitor Comparisons
A tool for mocking HTTP services
Pros of WireMock
- More extensive documentation and community support
- Better support for stateful mocking scenarios
- Easier to set up and configure for simple use cases
Cons of WireMock
- Less flexible in terms of customization and extensibility
- Limited support for non-HTTP protocols
- Slightly slower performance for high-volume scenarios
Code Comparison
MockServer:
new MockServerClient("localhost", 1080)
.when(
request()
.withMethod("GET")
.withPath("/example")
)
.respond(
response()
.withStatusCode(200)
.withBody("Hello, World!")
);
WireMock:
stubFor(get(urlEqualTo("/example"))
.willReturn(aResponse()
.withStatus(200)
.withBody("Hello, World!")));
Both MockServer and WireMock are popular mocking frameworks for testing HTTP-based applications. MockServer offers more flexibility and supports a wider range of protocols, making it suitable for complex testing scenarios. WireMock, on the other hand, is easier to set up and use for simpler HTTP mocking needs. The code comparison shows that both frameworks have similar syntax for basic request stubbing, with MockServer using a client-based approach and WireMock using a more declarative style.
Industry standard API mocking for JavaScript.
Pros of MSW
- Works in both browser and Node.js environments, allowing for consistent mocking across frontend and backend
- Integrates seamlessly with modern frontend frameworks and testing libraries
- Uses Service Workers, providing a more realistic network simulation
Cons of MSW
- Requires more setup and configuration compared to MockServer
- May have a steeper learning curve for developers unfamiliar with Service Workers
- Limited to HTTP and fetch API mocking, while MockServer supports multiple protocols
Code Comparison
MockServer:
new MockServerClient("localhost", 1080)
.when(
request()
.withMethod("GET")
.withPath("/users")
)
.respond(
response()
.withStatusCode(200)
.withBody("{ \"users\": [] }")
);
MSW:
rest.get('/users', (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({ users: [] })
)
})
Both MockServer and MSW are powerful mocking tools, but they cater to different use cases. MockServer is more versatile in terms of protocol support and has a longer track record, while MSW excels in frontend and API mocking scenarios, offering a more modern approach with its Service Worker integration.
Get a full fake REST API with zero coding in less than 30 seconds (seriously)
Pros of json-server
- Simpler setup and configuration, ideal for quick prototyping
- Automatic generation of RESTful routes based on JSON data
- Supports filters, pagination, and sorting out of the box
Cons of json-server
- Limited customization options for complex scenarios
- Lacks advanced features like request matching and verification
- Not suitable for simulating complex API behaviors or stateful interactions
Code Comparison
json-server:
// db.json
{
"posts": [
{ "id": 1, "title": "json-server", "author": "typicode" }
]
}
// Start server
json-server --watch db.json
MockServer:
new MockServerClient("localhost", 1080)
.when(
request()
.withMethod("GET")
.withPath("/posts")
)
.respond(
response()
.withStatusCode(200)
.withBody("[{\"id\": 1, \"title\": \"mockserver\", \"author\": \"mock-server\"}]")
);
MockServer offers more granular control over request matching and response generation, while json-server provides a simpler approach for basic REST API mocking. json-server is better suited for rapid prototyping and simple scenarios, whereas MockServer excels in complex, stateful API simulations and detailed request verification.
HTTP Request & Response Service, written in Python + Flask.
Pros of httpbin
- Simpler setup and usage, ideal for quick API testing
- Supports a wide range of HTTP methods and status codes
- Lightweight and easy to deploy
Cons of httpbin
- Limited customization options for responses
- Lacks advanced features like request matching and verification
Code Comparison
MockServer:
new MockServerClient("localhost", 1080)
.when(
request()
.withMethod("GET")
.withPath("/some/path")
)
.respond(
response()
.withStatusCode(200)
.withBody("Hello World!")
);
httpbin:
@app.route('/get')
def get():
return jsonify(
args=request.args,
headers=dict(request.headers),
origin=request.remote_addr
)
Key Differences
- MockServer offers more advanced features for mocking and verifying API behavior
- httpbin is primarily designed for testing HTTP clients and debugging
- MockServer provides a more comprehensive set of tools for API simulation
- httpbin is easier to set up and use for simple HTTP request testing
- MockServer allows for more complex request matching and response generation
- httpbin is better suited for quick, ad-hoc API testing scenarios
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
MockServer

Documentation
For usage guide please see: www.mock-server.com
Change Log
Please see: Change Log
Community
Chat | ![]() |
Feature Requests | ![]() |
Issues / Bugs | ![]() |
Backlog | ![]() |
Versions
Maven Central 
Maven Central contains the following MockServer artifacts:
- mockserver-netty - an HTTP(S) web server that mocks and records requests and responses
- mockserver-netty:shaded - mockserver-netty (as above) with all dependencies embedded
- mockserver-war - a deployable WAR for mocking HTTP(S) responses (for any JEE web server)
- mockserver-proxy-war - a deployable WAR that records requests and responses (for any JEE web server)
- mockserver-maven-plugin - a maven plugin to start, stop and fork MockServer using maven
- mockserver-client-java - a Java client to communicate with both the server and the proxy
In addition MockServer SNAPSHOT artifacts can also be found on Sonatype.
Node Module & Grunt Plugin
NPM Registry contains the following module:
- mockserver-node - a Node.js module and Grunt plugin to start and stop MockServer
- mockserver-client-node - a Node.js client for both the MockServer and the proxy
Docker Hub
Docker Hub contains the following artifacts:
- MockServer Docker Container - a Docker container containing the Netty MockServer and proxy
Helm Chart
- MockServer Helm Chart - a Helm Chart that installs MockServer to a Kubernetes cluster, available versions:
MockServer Clients
- mockserver-client-ruby
- Ruby client for both the MockServer and the proxy
- mockserver-client-java - a Java client for both the MockServer and the proxy
- mockserver-client-node - a Node.js and browser client for both the MockServer and the proxy
- kotest-extensions-kotest - Kotlin Kotest integration with MockServer
Previous Versions
Issues
If you have any problems, please check the project issues and avoid opening issues that have already been fixed. When you open an issue please provide the following information:
- MockServer version (i.e. 5.15.0)
- How your running the MockServer (i.e maven plugin, docker, etc)
- MockServer log output, at INFO level (or higher)
- What the error is
- What you are trying to do
Contributions
Pull requests are, of course, very welcome! Please read our contributing to the project guide first. Then head over to the open issues to see what we need help with. Make sure you let us know if you intend to work on something. Also check out to see what is already in the backlog.
Feature Requests
Feature requests are submitted to github issues. Once accepted they will be added to the backlog. Please check out to see what is already in the backlog.
Maintainers
Top Related Projects
A tool for mocking HTTP services
Industry standard API mocking for JavaScript.
Get a full fake REST API with zero coding in less than 30 seconds (seriously)
HTTP Request & Response Service, written in Python + Flask.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot