generate
Build HTTP request(s) from parameters and export. Supports single requests, batch derivation with transforms, and all export formats.
Usage
bash
request-mock generate -X <method> -u <url> [flags]Flags
| Flag | Short | Default | Description |
|---|---|---|---|
--method | -X | GET | HTTP method |
--url | -u | — | Request URL (required) |
--header | -H | — | Request header, repeatable, Name: Value |
--cookie | — | — | Request cookie, repeatable, name=value |
--query | -Q | — | Query param, repeatable, name=value |
--data | -d | — | Body (defaults to application/json) |
--data-raw | — | — | Raw body, pair with --post-mime |
--form | -F | — | Form param, repeatable |
--post-mime | — | — | Body MIME (with --data-raw) |
--status | — | 0 | Response status code |
--status-text | — | — | Response status text |
--resp-header | — | — | Response header, repeatable |
--resp-body | — | — | Response body |
--resp-mime | — | — | Response body MIME |
--server-ip | — | — | Server IP |
--format | -f | json | Export format |
--output | -o | — | Output file (default stdout) |
--raw | — | false | Bare output (no envelope) |
--creator | — | — | HAR creator, Name/Version |
--browser | — | — | HAR browser, Name/Version |
--count | -n | 1 | Batch derivation count |
--seed | — | 0 | Deterministic seed |
--transform | — | — | Transform names, repeatable |
Examples
bash
# Single POST with body
request-mock generate -X POST -u https://api.example.com/login \
-H 'Content-Type: application/json' \
-d '{"username":"alice","password":"secret"}'
# Batch 50 with seed
request-mock generate -X GET -u https://api.example.com/users -n 50 --seed 42 -f jsonl
# With explicit transforms (overrides default set)
request-mock generate -X GET -u https://api.example.com/users -n 50 --seed 42 \
--transform port --transform host
# Mock a 500 response
request-mock generate -X GET -u https://api.example.com/x --status 500 --status-text 'Internal Server Error'
# Raw curl to a file
request-mock generate -X GET -u https://api.example.com/users -f curl --raw -o users.shBatch derivation flow
When -n > 1 or --transform is set, generate enters the derivation path:
mermaid
flowchart LR
Spec["Base RequestSpec"] --> Gen["NewGenerator(seed)"]
Gen --> GS["GenerateSpecs(spec, n, transforms...)"]
GS --> Loop{"for i in 0..n"}
Loop -->|each| Clone["cloneSpec(base)"]
Clone --> TF{"apply transforms"}
TF --> T1["server_ip"]
T1 --> T2["user_agent"]
T2 --> T3["..."]
T3 --> Out["derived spec #i"]
Out --> Loop
Loop -->|done| Build["Generate(specs)"]
Build --> H["*har.Har (n entries)"]
style Spec fill:#e1f5ff
style H fill:#e8f5e9Determinism
Same --seed + same base spec + same transform list ⇒ identical output across runs and machines. This is the cornerstone for reproducible evaluation datasets.
bash
$ request-mock generate -X GET -u https://api.example.com/users -n 3 --seed 42 -f jsonl --raw | head -1
# identical on any machine