Skip to main content

A terminal TUI for defining REST mock endpoints while serving them locally.

Project description

Termimock

Termimock is a terminal API mock server with a TUI. Define mock REST endpoints from your terminal while the HTTP server is already running, then point your frontend at it immediately.

Most mock tools make you switch to a GUI, export config, or restart a process. Termimock keeps the control panel and the mock server together in one terminal session.

Termimock web GUI

Features

  • Live local HTTP server and terminal UI in the same process
  • Add, edit, duplicate, delete, enable, and disable mock endpoints
  • Match by HTTP method and path
  • Custom status code, content type, response body, and headers
  • Path parameters such as /api/users/:id or /api/users/{id}
  • Response templates such as {{params.id}}, {{query.q}}, {{method}}, and {{path}}
  • Per-route latency simulation
  • Multiple responses per route with first, cycle, or random selection
  • JSON request body matching with fields like email or user.email
  • Request log visible inside the TUI
  • Built-in browser GUI at /_termimock
  • Save and load endpoint definitions as JSON
  • Hot reload route files while the server is running
  • Import starter routes from OpenAPI JSON
  • Headless mode for CI, demos, and scripted frontend work
  • Zero runtime dependencies

Install

python3 -m pip install -e .

After the package is published to PyPI:

pipx install termimock

or:

python3 -m pip install termimock

Run the TUI

termimock

By default the server listens on http://127.0.0.1:8080.

termimock --host 127.0.0.1 --port 9000 --file examples/sample-routes.json

Run Without the TUI

termimock --headless --file examples/sample-routes.json

Open the built-in GUI:

http://127.0.0.1:8080/_termimock

The GUI lets you add, edit, duplicate, delete, enable, disable, and save routes from a browser while the mock server keeps running.

Route files reload automatically when changed. Use --no-watch to disable that behavior.

Import OpenAPI

Generate a starter route file from an OpenAPI JSON document:

termimock --import-openapi openapi.json --file routes.json

Then run it:

termimock --file routes.json

Then test it:

curl http://127.0.0.1:8080/api/user

Try a templated route:

curl "http://127.0.0.1:8080/api/users/42?tab=settings"

If port 8080 is already busy, choose another port:

termimock --headless --port 9000 --file examples/sample-routes.json

TUI Shortcuts

Key Action
a Add endpoint
e Edit selected endpoint
d Delete selected endpoint
c Clone selected endpoint
space Enable or disable selected endpoint
s Save routes
r Reload routes from disk
j / k or arrows Move selection
q Quit

Route File Format

{
  "routes": [
    {
      "method": "GET",
      "path": "/api/user",
      "status": 200,
      "content_type": "application/json",
      "headers": {
        "X-Mock": "termimock"
      },
      "body": "{\"id\":1,\"name\":\"Ada\"}",
      "delay_ms": 0,
      "enabled": true
    }
  ]
}

Path parameters can use either :id or {id} syntax. Response bodies can reference {{params.id}}, {{query.name}}, {{method}}, and {{path}}.

Routes can also define response variants:

{
  "method": "GET",
  "path": "/api/flaky",
  "response_mode": "cycle",
  "responses": [
    {
      "status": 200,
      "content_type": "application/json",
      "headers": {},
      "body": "{\"ok\":true}"
    },
    {
      "status": 500,
      "content_type": "application/json",
      "headers": {},
      "body": "{\"ok\":false}"
    }
  ]
}

POST routes can match JSON request bodies:

{
  "method": "POST",
  "path": "/api/login",
  "body_match": {
    "email": "admin@test.com"
  },
  "body": "{\"token\":\"dev-token\",\"email\":\"{{body.email}}\"}"
}

Project Status

This is an early, hackable version meant to prove the idea cleanly. Good next features are latency simulation, path parameters, request body matching, response presets, import from OpenAPI, and a richer route editor.

Development

PYTHONPATH=src python3 -m unittest discover -s tests

Releases

GitHub Releases are created from version tags. A release builds and attaches the Python wheel and source archive.

git tag v0.1.0
git push origin v0.1.0

Publishing a GitHub Release also publishes the package to PyPI through Trusted Publishing.

Container Package

Termimock publishes a container image to GitHub Container Registry.

docker run --rm -p 8080:8080 ghcr.io/homiyano/termimock:main

Open the GUI at:

http://127.0.0.1:8080/_termimock

Project details


Download files

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

Source Distribution

termimock-0.1.0.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

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

termimock-0.1.0-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file termimock-0.1.0.tar.gz.

File metadata

  • Download URL: termimock-0.1.0.tar.gz
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for termimock-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0c90a3dd8c9e1bfdcf788be01715f82961feca1a9ea470ed5571e2d73c348691
MD5 e53bfb92af9b07420cc532bccb64131b
BLAKE2b-256 a2e224e66245a803d67502d97f2c7c5aa6f4db1ab8af16953f034962f4f4de17

See more details on using hashes here.

Provenance

The following attestation bundles were made for termimock-0.1.0.tar.gz:

Publisher: pypi.yml on homiyano/termimock

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file termimock-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: termimock-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for termimock-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 39ed8f93a4d5915c9004aad4fa8ca875e9840d094acb823f0a8c02fe05ed7bfc
MD5 7e9a2e4d6818c49accf0545687a48efb
BLAKE2b-256 8d4545c5c866b82d6e2f3a915e50edfb65acc4545b3b152024c857d3e8a3dd5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for termimock-0.1.0-py3-none-any.whl:

Publisher: pypi.yml on homiyano/termimock

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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