hitspec mock
Start an HTTP mock server that responds based on requests and assertions defined in your hitspec files.Arguments
| Argument | Description |
|---|---|
<file> | Single .http or .hitspec file to derive routes from |
<directory> | Directory containing test files (searched recursively) |
Flags
| Flag | Short | Description | Default |
|---|---|---|---|
--port | -p | Port to run the mock server on | 3000 |
--delay | -d | Artificial delay for all responses (e.g., 100ms, 1s) | 0 |
--verbose | -v | Enable verbose logging | false |
Behavior
The mock server:- Parses your
.httpfiles to extract routes (method + URL path) - Generates mock responses from assertion blocks or explicit mock definitions
- Supports path parameters (e.g.,
/users/{{id}}) - Adds configurable response delays to simulate network latency
- Handles graceful shutdown on
Ctrl+C(SIGINT/SIGTERM)
Examples
Sample Output
Use Cases
- Frontend development — Run a mock backend while building the UI without needing the real API.
- Offline testing — Test client code against a local server when the real API is unavailable.
- Prototyping — Quickly stand up a fake API from your test definitions.
- Integration tests — Use the mock server as a dependency in your CI pipeline.
hitspec record
Start an HTTP recording proxy that captures requests and responses, then exports them to hitspec format.Flags
| Flag | Short | Description | Default |
|---|---|---|---|
--port | -p | Port to run the proxy on | 8080 |
--target | -t | Target URL to proxy to (required) | |
--output | -o | Output file path | stdout |
--exclude | Paths to exclude from recording (comma-separated) | ||
--verbose | -v | Enable verbose logging | false |
--dedupe | Skip duplicate requests (same method + path) | false | |
--json | Export as JSON instead of .http format | false |
Behavior
The recording proxy:- Forwards all requests to the target server (reverse proxy mode)
- Records both requests and responses
- Sanitizes sensitive headers (Authorization, Cookie, etc.)
- Exports to
.httpformat on shutdown (Ctrl+C) - Supports deduplication of repeated requests
Examples
Workflow
-
Start the recording proxy pointing at your real API:
-
Configure your client or browser to use
http://localhost:8080as the API base URL. - Perform the actions you want to capture (login, CRUD operations, etc.).
-
Press
Ctrl+Cto stop the proxy. The recorded requests are exported to the output file. -
Edit the generated
.httpfile to add assertions and parameterize values.
Sample Output
Use Cases
- Bootstrap test suites — Record real API traffic and convert it into test files automatically.
- Regression testing — Capture a working session and replay it as tests.
- API exploration — Discover endpoints and their expected responses by interacting with the real API.
- Documentation — Generate
.httpfiles that document actual API usage patterns.