Resterm allows you to declare mock servers directly within your .http files using @mock directives. This enables you to mimic API behavior alongside your actual requests.
Key Features
- Matching: Match requests by method, path, query, headers, or JSON body.
- Sequences: Model polling or retry flows with response sequences.
- Dynamic Data: Build responses using generators for path, query, header, and body values.
- Verification: Use
@expect to verify call counts.
Example: Multiple scenarios on one route
In the example below, the first mock is the default response, while the second is triggered only when specific query, header, and JSON body conditions are met.
### Payment accepted
# @mock method=POST path=/payments name=accepted default=true latency=150ms
HTTP/1.1 202 Accepted
Content-Type: application/json
{"id":"pay_123","status":"pending"}
### Payment declined
# @mock method=POST path=/payments name=declined
# @match query={"mode":"decline"} headers={"X-Tenant":"demo"} json={"amount":0}
HTTP/1.1 422 Unprocessable Entity
Content-Type: application/json
{"error":"amount must be positive"}
Running the Mock Server
You can serve a single file or a directory recursively:
# Serve a single file
resterm mock ./requests.http
# Serve a directory recursively on a specific address
resterm mock --recursive --addr 127.0.0.1:9090 ./requests
### Payment accepted
# @mock method=POST path=/payments name=accepted default=true latency=150ms
HTTP/1.1 202 Accepted
Content-Type: application/json
{"id":"pay_123","status":"pending"}
### Payment declined
# @mock method=POST path=/payments name=declined
# @match query={"mode":"decline"} headers={"X-Tenant":"demo"} json={"amount":0}
HTTP/1.1 422 Unprocessable Entity
Content-Type: application/json
{"error":"amount must be positive"}