Sign inSign up

daxart/mockser

By daxart

Updated over 2 years ago

Configurable mock server for testing and development

Image
0

459

daxart/mockser repository overview

Mockser

Configurable mock server for testing and development.

The project contains the implementation of a mock server that allows configuring and handling mock requests. The server listens on a specified host and port, and provides an HTTP endpoint for configuring mocks.

The server also listens on a separate port for configuration requests, allowing dynamic updates to the mock configurations.

To configure a mock, send a POST request to the /configure endpoint with the mock configuration in the request body. The mock configuration should include the request URI, method, body, and headers, as well as the response code, body, and headers.

The server matches incoming requests with the configured mocks based on the request path. If a matching mock is found, it constructs an HTTP response using the mock's response code, body, and headers. If no matching mock is found, it returns a 404 Not Found response.

Usage

docker run --rm -p 3000:3000 -p 3001:3001 daxart/mockser
POST http://127.0.0.1:3001/configure
{
    "name": "Test request",
    "request": {
        "path": "/test",
        "method": "POST",
        "headers": {
            "content-type": "application/json"
        }
    },
    "response": {
        "code": 201,
        "body": "{\"name\":\"Test response\"}",
        "headers": {
            "content-type": "application/json",
            "x-custom-header": "custom-value"
        }
    }
}

HTTP 201

POST http://127.0.0.1:3000/test?param1=value1&param2=value2
Content-Type: application/json
{
    "name": "Test request"
}

HTTP 201
[Asserts]
header "Content-Type" == "application/json"
header "X-Custom-Header" == "custom-value"
body == "{\"name\":\"Test response\"}"

Configuration

The server can be configured using environment variables.

nametypedefaultoptions
MOCKSER_HOSTstring'0.0.0.0'
MOCKSER_PORTnumber3000
MOCKSER_CONFIG_PORTnumber3001
MOCKSER_INITIAL_CONFIGSpathNone
MOCKSER_LOGstring'info'...
MOCKSER_LOG_STYLEstring'auto'auto, always, never
MOCKSER_LOG_FORMATstring'human'human, json

Tag summary

Content type

Image

Digest

sha256:11feaf9ba

Size

5.8 MB

Last updated

over 2 years ago

docker pull daxart/mockser