Skip to main content

A mini mock server for http requests

Project description

Mini Mock Server

A mini mock server for http requests.

Features

  • Start an HTTP mock server without installing any web framework.
  • Delay requests to simulate slow endpoints using the response.sleep attribute.
  • Return random responses on the same route to simulate different kind of responses.

Important Notices

Currently, the mini-mock-server uses the http.server to start a new server, which is not recommended for production environments. The http.server only implements basic security checks. See the official documentation for more information.

Installation

pip install mini-mock-server

Usage

  1. Create a mock-api.json file for route specifications.
{
    "/": [
        {
            "url": "/users",
            "method": "GET",
            "response": [
                {
                    "status_code": 200,
                    "body": [
                        {"id": 1, "name": "Mario"},
                        {"id": 2, "name": "Luigi"}
                    ]
                },
                {
                    "sleep": 1,
                    "status_code": 400,
                    "body": {"error": "Bad request custom message"}
                }
            ]
        }
    ],
    "/api": [
        {
            "url": "/products/:id",
            "method": "GET",
            "response": {
                "status_code": 200,
                "body": {
                    "id": 1,
                    "name": "Product 001",
                    "price": 115.51
                }
            }
        }
    ]
}
  1. Start the mock server.
mini-mock-server mock-api.json

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mini_mock_server-0.0.28-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file mini_mock_server-0.0.28-py3-none-any.whl.

File metadata

File hashes

Hashes for mini_mock_server-0.0.28-py3-none-any.whl
Algorithm Hash digest
SHA256 ae11389cab9479debc5a4ed72e691d987910cd93067bf57f1c2fa7f939466b41
MD5 2e622eec5b7b2d26aa23addc7483a00b
BLAKE2b-256 0a2f4b9bb5f037e54e9e52619b4781448882620684e9d124c10775f2053f7111

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page