A TUI-based HTTP mock server for development
  • Rust 91.8%
  • Shell 8.2%
Find a file
Ivan Exposito 1006376daf
Some checks failed
CI / Format Check (push) Successful in 39s
CI / Clippy Lints (push) Successful in 2m27s
CI / Unit Tests (push) Successful in 4m27s
CI / Build Verification (push) Successful in 7m0s
Release / Build aarch64-unknown-linux-gnu (push) Failing after 3m5s
Release / Build aarch64-unknown-linux-musl (push) Failing after 3m2s
CI / Security Audit (push) Successful in 10m27s
Release / Build x86_64-pc-windows-gnu (push) Failing after 3m3s
CI / E2E Tests (push) Successful in 8s
Release / Build x86_64-unknown-linux-gnu (push) Failing after 6m22s
Release / Build x86_64-unknown-linux-musl (push) Failing after 2m8s
Release / Create Release (push) Has been skipped
chore: bump version to v0.4.0
2026-02-21 17:19:18 +01:00
.forgejo/workflows ci: add cargo audit job to catch dependency vulnerabilities 2026-02-16 19:52:54 +01:00
dist docs: update repository URLs and binary name references 2026-02-05 18:26:56 +01:00
examples test: add comprehensive e2e test suite using curl 2026-02-03 20:10:05 +01:00
src style: fix rustfmt formatting 2026-02-21 17:01:04 +01:00
tests/e2e fix: handle CORS credentials with wildcard headers/methods 2026-02-16 21:08:20 +01:00
.gitignore feat: add headless mode for CI e2e tests 2026-02-04 22:15:33 +01:00
Cargo.lock chore: bump version to v0.4.0 2026-02-21 17:19:18 +01:00
Cargo.toml chore: bump version to v0.4.0 2026-02-21 17:19:18 +01:00
Cross.toml fix: make CI/CD workflows compatible with Forgejo Actions 2026-02-03 22:32:09 +01:00
LICENSE chore: prepare for crates.io publishing 2026-02-04 22:57:06 +01:00
mockr-schema.json feat: add JSON schema for editor autocompletion 2026-02-16 18:25:44 +01:00
README.md docs: update README with new TUI features and keybindings 2026-02-21 16:51:08 +01:00
rust-toolchain.toml fix: make CI/CD workflows compatible with Forgejo Actions 2026-02-03 22:32:09 +01:00

mockr-tui

                      _            _         _
 _ __ ___   ___   ___| | ___ __   | |_ _   _(_)
| '_ ` _ \ / _ \ / __| |/ / '__|  | __| | | | |
| | | | | | (_) | (__|   <| |     | |_| |_| | |
|_| |_| |_|\___/ \___|_|\_\_|      \__|\__,_|_|

Crates.io License: MIT

A TUI-based HTTP mock server for development.


Features

Core Advanced Developer Experience
Path parameters ({id}) Weighted multi-response Terminal UI with live logs
Catch-all patterns ({*path}) Conditional responses Hot-reload configuration
CORS support Response templating Runtime port settings
Configurable delays JSONPath body matching Request filtering & detail search
JSON syntax highlighting
Export log to JSON / copy curl
Endpoint detail preview
Stats bar with request counts

Quick Start

# 1. Install
cargo install mockr-tui

# 2. Create config
mockr --init

# 3. Run
mockr

That's it! Your mock server is running at http://127.0.0.1:8080.



Installation

Package Managers

Cargo (recommended):

cargo install mockr-tui

Cargo binstall (faster, pre-built binary):

cargo binstall mockr-tui

Arch Linux (AUR):

yay -S mockr-tui      # From source
yay -S mockr-tui-bin  # Pre-built binary

Pre-built Binaries

Download from the releases page.

Linux:

curl -fsSL https://code.byjokese.net/byjokese/mockr-tui/raw/branch/main/dist/install.sh | sh

Windows (PowerShell):

irm https://code.byjokese.net/byjokese/mockr-tui/raw/branch/main/dist/install.ps1 | iex

Build from Source

git clone https://code.byjokese.net/byjokese/mockr-tui.git
cd mockr-tui
cargo install --path .

Usage

mockr                    # Use default mockr.json
mockr -c config.json     # Use specific config file
mockr -p 3000            # Override port
mockr --headless         # Run without TUI (server only)

CLI Options

Option Default Description
-c, --config <FILE> mockr.json Path to configuration file
-p, --port <PORT> from config Override server port
-H, --host <HOST> from config Override server host
--no-watch false Disable hot reload
--headless false Run HTTP server only (no TUI)
--init - Create a starter configuration file

Configuration

Basic Example

{
  "server": {
    "host": "127.0.0.1",
    "port": 8080
  },
  "endpoints": [
    {
      "name": "Get Users",
      "path": "/api/users",
      "method": "GET",
      "response": {
        "status": 200,
        "body": [
          { "id": 1, "name": "Alice" },
          { "id": 2, "name": "Bob" }
        ]
      }
    }
  ]
}

Server Options

Option Default Description
host 127.0.0.1 Host to bind to
port 8080 Port to listen on
cors.enabled true Enable CORS
cors.origins ["*"] Allowed origins
cors.methods ["GET", "POST", ...] Allowed methods
cors.allow_credentials true Allow credentials (cookies, auth headers). When true with wildcard origins, the server mirrors the request Origin header instead of sending *

Endpoint Options

Option Required Description
path Yes URL path pattern
method Yes HTTP method (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS, ANY)
name No Human-readable name
description No Description
enabled No Active state (default: true)
response No Single response configuration
responses No Multiple weighted/conditional responses
delay_ms No Fixed response delay (ms)
delay_range_ms No Random delay range [min, max]
priority No Higher priority matches first (default: 0)

Path Patterns

/api/users           # Exact match
/api/users/{id}      # Path parameter - captures "id"
/files/{*path}       # Catch-all - captures entire remaining path

Response Options

Option Default Description
status 200 HTTP status code
headers {} Response headers
body null Response body (string or JSON)
body_file - Path to file containing response body
content_type application/json Content-Type header

Request Matching

Match requests based on headers, query parameters, or body content:

{
  "path": "/api/data",
  "method": "POST",
  "request": {
    "headers": { "Authorization": "Bearer.*" },
    "query_params": { "type": "admin" },
    "body_contains": "important",
    "body_json_path": { "$.user.role": "admin" }
  },
  "response": {
    "status": 200,
    "body": { "matched": true }
  }
}
Matcher Description
headers Match request headers (supports regex)
query_params Match query string parameters
body_contains Match if body contains substring
body_json_path Match JSON body using JSONPath expressions

Response Templating

Response bodies and headers support dynamic template variables:

Variable Description
{{timestamp}} ISO 8601 timestamp
{{timestamp_unix}} Unix timestamp (seconds)
{{uuid}} Random UUID v4
{{request.method}} HTTP method
{{request.path}} Request path
{{request.query}} Query string
{{request.header.Name}} Request header value
{{path.param}} Path parameter value
{
  "path": "/api/users/{id}",
  "method": "GET",
  "response": {
    "headers": { "X-Request-Id": "{{uuid}}" },
    "body": {
      "id": "{{path.id}}",
      "requested_at": "{{timestamp}}"
    }
  }
}

Multiple Responses

Weighted random selection:

{
  "path": "/api/flaky",
  "method": "GET",
  "responses": [
    { "status": 200, "body": { "ok": true }, "weight": 8 },
    { "status": 500, "body": { "error": "Server error" }, "weight": 2 }
  ]
}

Conditional responses:

{
  "path": "/api/users",
  "method": "GET",
  "responses": [
    {
      "when": { "headers": { "X-Admin": "true" } },
      "status": 200,
      "body": { "users": ["all", "users"] }
    },
    {
      "status": 200,
      "body": { "users": ["public", "only"] }
    }
  ]
}

The first matching when condition is selected; responses without when act as fallback.


Keyboard Shortcuts

Key Action
Tab / Shift+Tab Next / previous panel
1 / 2 / 3 Jump to panel
/ k, / j Navigate up/down
PgUp / PgDn Page up/down
Home / End Go to top/bottom
Ctrl+u / Ctrl+d Half-page scroll (Detail View)
Enter View details (request or endpoint)
Space Toggle endpoint
r Reload config
c Clear request log
e Export log to JSON
y Copy curl command to clipboard
Y Copy response body to clipboard
/ Start filtering (Request Log) / search (Detail View)
n / N Next / previous search match (Detail View)
s Settings
? / F1 Show help
Esc Close popup / Clear filter or search
q / Ctrl+c Quit

Editor Autocompletion

The --init command includes a $schema reference for JSON autocompletion. If your editor reports the URL as untrusted, add the domain to your editor's trusted schemas:

VS Code — add to settings.json:

{
  "json.schemas": [
    {
      "fileMatch": ["mockr.json"],
      "url": "https://code.byjokese.net/byjokese/mockr-tui/raw/branch/main/mockr-schema.json"
    }
  ]
}

Alternatively, download mockr-schema.json to your project and use "$schema": "./mockr-schema.json".

License

MIT