Convert Figma logo to code with AI

mock-server logomockserver

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).

4,712
1,090
4,712
282

Top Related Projects

A tool for mocking HTTP services

16,626

Industry standard API mocking for JavaScript.

Get a full fake REST API with zero coding in less than 30 seconds (seriously)

13,080

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

  1. Creating a simple expectation:
new MockServerClient("localhost", 1080)
    .when(
        request()
            .withMethod("GET")
            .withPath("/hello")
    )
    .respond(
        response()
            .withStatusCode(200)
            .withBody("Hello, World!")
    );
  1. Verifying a request:
new MockServerClient("localhost", 1080)
    .verify(
        request()
            .withMethod("POST")
            .withPath("/api/data")
            .withBody("{\"key\": \"value\"}")
    );
  1. Setting up a proxy:
new MockServerClient("localhost", 1080)
    .forward(
        request()
            .withPath("/api/.*"),
        forward()
            .withHost("api.example.com")
    );

Getting Started

  1. Add MockServer dependency to your project:
<dependency>
    <groupId>org.mock-server</groupId>
    <artifactId>mockserver-netty</artifactId>
    <version>5.14.0</version>
</dependency>
  1. Start MockServer in your test:
MockServer mockServer = ClientAndServer.startClientAndServer(1080);

// Your test code here

mockServer.stop();
  1. 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.

16,626

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.

13,080

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 Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

MockServer            Tweet Build status GitHub license GitHub stars Trello Backlog  Join Slack

Documentation

For usage guide please see: www.mock-server.com

Change Log

Please see: Change Log

Community

Chat Join Slack
Feature Requests GitHub Issues
Issues / Bugs GitHub Issues
Backlog Trello Backlog

Versions

Maven Central mockserver

Maven Central contains the following MockServer artifacts:

In addition MockServer SNAPSHOT artifacts can also be found on Sonatype.

Node Module & Grunt Plugin

NPM Registry contains the following module:

Docker Hub

Docker Hub contains the following artifacts:

Helm Chart
MockServer Clients
Previous Versions
VersionDateGit & Docker Tag / Git HashDocumentationJava APIREST API
5.15.0 (latest)11 Jan 2023mockserver-5.15.0 / 7c071bDocumentationJava API5.15.x REST API
5.14.022 Aug 2022mockserver-5.14.0 / 808ebaDocumentationJava API5.14.x REST API
5.13.205 Apr 2022mockserver-5.13.2 / 81105bDocumentationJava API5.13.x REST API
5.13.102 Apr 2022mockserver-5.13.1 / 39d1ccDocumentationJava API5.13.x REST API
5.13.017 Mar 2022mockserver-5.13.0 / 604888DocumentationJava API5.13.x REST API
5.12.012 Feb 2022mockserver-5.12.0 / 61747fDocumentationJava API5.12.x REST API
5.11.208 Nov 2020mockserver-5.11.2 / eb84f2DocumentationJava API5.11.x REST API
5.11.122 Jul 2020mockserver-5.11.1 / 361e5cDocumentationJava API5.11.x REST API
5.11.008 Jul 2020mockserver-5.11.0 / 756758DocumentationJava API5.11.x REST API
5.10.024 Mar 2020mockserver-5.10.0 / 14124dDocumentationJava API5.10.x REST API
5.9.001 Feb 2020mockserver-5.9.0 / eacf07DocumentationJava API5.9.x REST API
5.8.123 Dec 2019mockserver-5.8.1 / f0e9abDocumentationJava API5.8.x REST API
5.8.001 Dec 2019mockserver-5.8.0 / 7c9fc5DocumentationJava API5.8.x REST API
5.7.216 Nov 2019mockserver-5.7.2 / 7c9fc5DocumentationJava API5.7.x REST API
5.7.109 Nov 2019mockserver-5.7.1 / 0ca353DocumentationJava API5.7.x REST API
5.7.001 Nov 2019mockserver-5.7.0 / b58bc5DocumentationJava API5.7.x REST API
5.6.121 Jul 2019mockserver-5.6.1 / aec1fbDocumentationJava API5.6.x REST API
5.6.021 Jun 2019mockserver-5.6.0 / 8f82dcDocumentationJava API5.6.x REST API
5.5.426 Apr 2019mockserver-5.5.4 / 4ffd31DocumentationJava API5.5.x REST API
5.5.129 Dec 2018mockserver-5.5.1 / 11d8a9DocumentationJava API5.5.x REST API
5.5.015 Nov 2018mockserver-5.5.0 / 06e6fdDocumentationJava API5.5.x REST API

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 Trello Backlog 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 Trello Backlog to see what is already in the backlog.

Maintainers

NPM DownloadsLast 30 Days