Skip to content

REST API Reference

Everything the Madhyamas web UI and CLI do is powered by a REST API listening on the same port as the web UI (default 3001). All endpoints are under the /api prefix and return JSON unless otherwise noted. You can use this API directly to integrate Madhyamas into scripts, CI pipelines, dashboards, or custom tools.

Base URL and Conventions

  • Base URL: http://localhost:3001/api
  • Content type: application/json for request bodies and responses
  • Authentication: none by default. When the enterprise feature is enabled, supply a JWT via Authorization: Bearer <token> or an API key via X-API-Key: <key>.
  • Errors: non-2xx responses carry a JSON body of the form {"error": "...", "code": "..."}.
  • Real-time updates: connect to GET /ws (WebSocket) for live traffic events.

Health and Real-time

MethodPathDescription
GET/healthLiveness check — returns the text OK
GET/health/detailedVersion, uptime, memory, connection stats (enterprise)
GET/wsWebSocket upgrade for real-time traffic updates

WebSocket server events: Connected, InitialTraffic, Traffic (Added/Updated/Deleted/Cleared/CountUpdate), Pong, Error. Client messages: Ping, Subscribe (with optional filter), Unsubscribe, GetInitialTraffic.

Traffic

MethodPathDescription
GET/trafficList captured traffic (query: method, url, status_code, content_type, limit, offset)
GET/traffic/{id}Get a single traffic entry with full headers and body
GET/traffic/{id}/script-tracesGet script execution traces for a traffic entry
GET/traffic/countGet the total count of captured entries
POST/traffic/clearClear all captured traffic
POST/traffic/import/harImport a HAR JSON document into a new session
bash
# List the 50 most recent 500s
curl 'http://localhost:3001/api/traffic?status_code=500&limit=50'

# Import a HAR file
curl -X POST -H 'Content-Type: application/json' -d @capture.har \
  http://localhost:3001/api/traffic/import/har

Sessions

MethodPathDescription
GET/sessionsList all sessions
POST/sessionsCreate a session ({"name":"..."})
GET/sessions/{id}Get session details
DELETE/sessions/{id}Delete a session
GET/sessions/{id}/exportExport a session (?format=har)
POST/sessions/{id}/switchSwitch the active session
POST/sessions/importImport a session from JSON

Export

MethodPathDescription
GET/export/harExport all traffic as a HAR file
GET/export/curl/{id}Get a cURL command reproducing a request

Certificate

MethodPathDescription
GET/cert/caDownload the CA certificate (PEM)

Configuration

MethodPathDescription
GET/configGet the proxy configuration
PATCH/configUpdate configuration
GET/config/exportExport all configuration (enterprise)
POST/config/importImport configuration (enterprise)

PATCH /config accepts: intercept_https (boolean), max_requests (integer), max_body_size (integer), verbose (boolean), public_ip (string|null), passthrough_domains (array), enable_h2_downstream (boolean).

bash
curl -X PATCH http://localhost:3001/api/config \
  -H 'Content-Type: application/json' \
  -d '{"intercept_https":false,"max_requests":50000}'

Capture Mode

MethodPathDescription
GET/captureGet capture status (Recording or Passthrough)
POST/capture/toggleToggle capture mode
GET/capture/statsGet capture statistics

Auto Save

MethodPathDescription
GET/autosaveGet Auto Save configuration
PATCH/autosaveUpdate Auto Save configuration
POST/autosave/snapshotTrigger an immediate backup snapshot

PATCH /autosave accepts: enabled, interval_seconds, export_format (har|session), output_dir, max_backups, rotate_after_requests, rotate_after_minutes.

Breakpoints

MethodPathDescription
GET/breakpointsList all breakpoint rules
POST/breakpointsCreate a breakpoint rule
GET/breakpoints/{id}Get a specific rule
DELETE/breakpoints/{id}Delete a rule
GET/breakpoints/pausedList all paused traffic items
GET/breakpoints/paused/{id}Get a specific paused item
POST/breakpoints/paused/{id}/resumeResume with a decision: allow, modify, or reject

Mocks

MethodPathDescription
GET/mocksList all mock rules
POST/mocksCreate a mock rule
GET/mocks/templatesGet predefined mock templates
GET/mocks/{id}Get a specific mock
PUT/mocks/{id}Update a mock
DELETE/mocks/{id}Delete a mock
POST/mocks/{id}/toggleEnable/disable a mock
POST/mocks/batch-toggleToggle multiple mocks
POST/mocks/advancedCreate an advanced mock (tags, collection, description)
POST/mocks/{id}/duplicateDuplicate a mock
POST/mocks/{id}/rollbackRoll back a mock to a previous version
GET/mocks/{id}/versionsGet mock version history
POST/mocks/{id}/testTest a mock against a sample request
POST/mocks/previewPreview which mock matches a request
GET/mocks/exportExport all mocks as JSON
POST/mocks/importImport mocks (HAR/OpenAPI/Postman)

Mock Collections

MethodPathDescription
GET/mocks/collectionsList all collections
POST/mocks/collectionsCreate a collection
GET/mocks/collections/{id}Get a specific collection
PUT/mocks/collections/{id}Update collection metadata
DELETE/mocks/collections/{id}Delete a collection (optional delete_rules)
POST/mocks/collections/{id}/toggleToggle all mocks in a collection

Mock Recording

MethodPathDescription
POST/mocks/recordingEnable/disable recording mode
GET/mocks/recording/statusGet recording status
GET/mocks/recording/recordedGet recorded mocks
POST/mocks/recording/promotePromote recorded mocks to active rules
POST/mocks/recording/clearClear recorded mocks

Mock Analytics

MethodPathDescription
GET/mocks/analyticsGet hit analytics for all mocks
GET/mocks/{id}/analyticsGet hit stats for a specific mock
GET/mocks/{id}/historyGet hit history for a specific mock
POST/mocks/history/clearClear all hit history

Rewrites

MethodPathDescription
GET/rewritesList all rewrite rules
POST/rewritesCreate a rewrite rule
GET/rewrites/templatesGet predefined rewrite templates
GET/rewrites/{id}Get a specific rewrite
DELETE/rewrites/{id}Delete a rewrite
POST/rewrites/{id}/toggleEnable/disable a rewrite
POST/rewrites/batch-toggleToggle multiple rewrites

POST /rewrites body: name, condition (object), direction (request|response|both), rewrites (array of action objects), priority (optional).

Throttle

MethodPathDescription
GET/throttleGet the current throttle profile
POST/throttleSet the throttle profile
POST/throttle/enabledEnable/disable throttling
GET/throttle/presetsList throttle presets

POST /throttle body: download_bps, upload_bps, delay_ms, jitter_ms, packet_loss_percent, name, enabled.

Replay

MethodPathDescription
GET/replay/savedList saved requests
POST/replay/savedSave a request
GET/replay/saved/{id}Get a specific saved request
DELETE/replay/saved/{id}Delete a saved request
POST/replay/execute/{id}Replay a saved request
POST/replay/execute/{id}/batchBatch replay (iterations, concurrency, delay)
GET/replay/historyGet replay history
DELETE/replay/historyClear replay history

POST /replay/execute/{id}/batch body: iterations (max 10,000), concurrency (max 100), delay_ms, modifications (object — same shape as single replay).

Block List

MethodPathDescription
GET/blocklistList all block list entries
POST/blocklistCreate an entry
GET/blocklist/statsGet summary statistics
GET/blocklist/{id}Get a specific entry
PUT/blocklist/{id}Update an entry
DELETE/blocklist/{id}Delete an entry
POST/blocklist/{id}/toggleEnable/disable an entry

POST /blocklist body: pattern (required), note, enabled (default true), status_code (default 403), response_body, content_type.

Focus Hosts

MethodPathDescription
GET/focusList all focus host patterns
POST/focusAdd a focus host pattern
DELETE/focusClear all focus hosts
DELETE/focus/{id}Remove a specific focus host

POST /focus body: pattern (required) — exact hostname, wildcard subdomain (*.example.com), or glob (*api*).

Mirror

MethodPathDescription
GET/mirrorGet mirror status and statistics
POST/mirror/toggleToggle mirroring on/off
PATCH/mirror/configUpdate mirror configuration

PATCH /mirror/config body: enabled, output_dir, host_filter (array), save_request_bodies.

Logs

MethodPathDescription
GET/logsGet log rotation status (config, current file, archived files)
PATCH/logsUpdate log rotation configuration
POST/logs/rotateRotate the current log file immediately

PATCH /logs body: enabled, rotation ({"mode":"never"|"hourly"|"daily"} or {"mode":"size","size_mb":<n>}), max_files, max_file_size_mb, json_format.

Persistence

MethodPathDescription
GET/persistence/exportExport all rules (mocks, rewrites, breakpoints, throttle) as JSON
POST/persistence/importImport all rules from JSON
POST/persistence/saveSave rules to the persistent store (requires X-Madhyamas-Confirm: true)
POST/persistence/loadLoad rules from the persistent store

gRPC (feature: grpc)

MethodPathDescription
GET/grpc/connectionsList gRPC connections
GET/grpc/streamsList gRPC streams
GET/grpc/framesGet gRPC frames (filters: service, method, path, direction, status_code, limit)
GET/grpc/statsGet gRPC statistics
POST/grpc/clearClear all gRPC frames

WebSocket Traffic

MethodPathDescription
GET/ws-traffic/connectionsList WebSocket connections
GET/ws-traffic/connections/{id}Get a specific WebSocket connection
GET/ws-traffic/messagesGet WebSocket messages (filters: connection_id, direction, message_type, search)
POST/ws-traffic/clearClear WebSocket traffic

Scripts (feature: scripting)

MethodPathDescription
GET/scriptsList all scripts
POST/scriptsCreate a script
GET/scripts/templatesGet script templates
GET/scripts/configGet script runtime configuration
PUT/scripts/configUpdate script runtime configuration
GET/scripts/historyGet execution history across all scripts
POST/scripts/testDry-run a script against a sample context
POST/scripts/validateValidate a script's syntax without executing
POST/scripts/match-previewPreview which scripts would match a request
GET/scripts/{id}Get a specific script
PUT/scripts/{id}Update a script
DELETE/scripts/{id}Delete a script
POST/scripts/{id}/toggleEnable/disable a script
POST/scripts/{id}/reorderReorder a script (change priority)
GET/scripts/{id}/historyGet execution history for a specific script
DELETE/scripts/{id}/historyClear execution history for a specific script

POST /scripts body: name (1-255 chars), source (non-empty), description (optional), hooks (array, optional). PUT /scripts/config body: timeout_ms, memory_limit_mb, capture_console.

Plugins (feature: plugins)

MethodPathDescription
GET/pluginsList all plugins
GET/plugins/{id}Get a specific plugin
POST/plugins/{id}/enableEnable a plugin
POST/plugins/{id}/disableDisable a plugin
GET/plugins/{id}/statsGet plugin statistics
POST/plugins/reloadReload all plugins from disk
POST/plugins/installInstall a plugin from a URL or registry id
DELETE/plugins/{id}/uninstallUninstall a plugin
GET/plugins/{id}/settingsGet a plugin's current settings
PUT/plugins/{id}/settingsUpdate a plugin's settings
GET/plugins/{id}/schemaGet a plugin's settings schema
GET/plugins/{id}/panelsGet a plugin's declarative UI panels
GET/plugins/{id}/logsGet a plugin's recent invocation logs
GET/plugins/registryList all available plugins in the registry
GET/plugins/registry/searchSearch the registry (?q=...)
GET/plugins/registry/{id}Get a specific registry entry
GET/plugins/registry/configGet the registry configuration
PUT/plugins/registry/configUpdate the registry repository configuration
POST/plugins/registry/refreshForce-refresh the registry cache
GET/plugins/templatesList available plugin scaffolding templates
POST/plugins/scaffoldScaffold a new plugin project from a template

POST /plugins/install body: source (url|registry), url (when source=url), id (when source=registry), checksum (optional for URL source).

Enterprise Endpoints (feature-gated)

These endpoints are conditionally enabled and may require JWT authentication. Several are stubs returning NOT_IMPLEMENTED; see Enterprise for the feature matrix.

Performance and Monitoring

MethodPathDescription
GET/metricsPerformance metrics (request counts, latency, RPS)
GET/performancePerformance stats (metrics, memory, connection pool)

Authentication

MethodPathDescription
POST/auth/loginUser login (returns JWT)
POST/auth/logoutUser logout
GET/auth/meGet current user
POST/auth/validateValidate a JWT
GET/auth/api-keysList API keys
POST/auth/api-keysCreate an API key
DELETE/auth/api-keys/{id}Revoke an API key

User Management

MethodPathDescription
GET/usersList all users (admin)
POST/usersCreate a user (admin)
GET/users/{id}Get user details
PUT/users/{id}Update a user
DELETE/users/{id}Delete a user

RBAC

MethodPathDescription
GET/rbac/rolesList all roles
GET/rbac/permissionsList all permissions
POST/rbac/checkCheck if a user has a permission

Audit Logging

MethodPathDescription
GET/auditGet audit log entries (filters: event_types, user_id, resource, success, time range)
GET/audit/statsGet audit statistics
GET/audit/exportExport audit events
DELETE/audit/clearClear audit events

Onboarding

MethodPathDescription
GET/onboardingGet onboarding status
POST/onboarding/completeComplete an onboarding step
POST/onboarding/skipSkip onboarding

See also

Released under the MIT OR Apache-2.0 License.