hitspec contract
Verify API contracts against a live provider.Arguments
| Argument | Description |
|---|---|
<contracts-dir> | Directory containing contract .http files (or a single file) |
Flags
| Flag | Short | Description | Default |
|---|---|---|---|
--provider | -p | Provider URL (required) | |
--state-handler | Path to a state handler script | ||
--verbose | -v | Enable verbose output | false |
Contract Annotations
Define contract metadata using annotations in your.http files:
| Annotation | Description |
|---|---|
@contract.provider | Name of the provider service |
@contract.state | Provider state required for this interaction |
State Handler
The--state-handler flag specifies a script that sets up provider state before each interaction. The script receives the state description as an argument:
Examples
Sample Output
Use Cases
- Consumer-driven contracts — Define what your service expects from its dependencies, then verify those contracts against the real provider.
- API versioning — Ensure that provider changes do not break existing consumers.
- CI/CD gates — Run contract verification as part of the provider’s deployment pipeline.
hitspec diff
Compare two JSON test result files to identify regressions, improvements, and changes between test runs.Arguments
| Argument | Description |
|---|---|
<results1.json> | Baseline test results (JSON output from hitspec run --output json) |
<results2.json> | Current test results to compare against the baseline |
Flags
| Flag | Short | Description | Default |
|---|---|---|---|
--output | -o | Output format: console, json, html | console |
--threshold | Fail if any test is slower by this percentage (e.g., 10%) |
How It Works
The diff command compares tests by name and file, then categorizes each as:| Status | Meaning |
|---|---|
| improved | Test now passes (previously failed) or is >10% faster |
| regressed | Test now fails (previously passed) or is >10% slower |
| unchanged | No significant change in status or duration |
| new | Test exists only in the second result file |
| removed | Test exists only in the first result file |
Generating Input Files
First, generate JSON results from your test runs:Examples
Console Output
Threshold Check
When--threshold is set, the command exits with a non-zero status if any test’s duration increases by more than the specified percentage. This is useful for catching performance regressions in CI: