Skip to content

template / batch ​

template — built-in scenario templates ​

Use pre-defined request patterns without manually specifying every field.

bash
request-mock template --list                       # list all
request-mock template --name login -f curl         # use login template
request-mock template --name postjson --url https://api.example.com/users -f har --raw

Built-in templates (15) ​

NameMethodURLDescription
getjsonGET/usersJSON API fetch
postjsonPOST/dataJSON body POST
postformPOST/formForm-encoded POST
loginPOST/loginLogin with username/password
uploadPOST/uploadFile upload (multipart)
bearerGET/meBearer token auth
deleteDELETE/resourceREST DELETE
putPUT/resourceREST PUT
patchPATCH/resourceREST PATCH
headHEAD/HEAD request
optionsOPTIONS/OPTIONS request
bannerGET/bannerBanner image fetch
redirectGET/Redirect chain
errorGET/errorError page (500)
portscanGET/Nmap-style port scan

Template override ​

--url and --method can override the template defaults. Template headers/cookies/body are preserved unless you also pass overriding flags.

batch — config-driven bulk generation ​

bash
request-mock batch --config config.yaml -o out.curl
request-mock batch --config config.yaml -n 100 --seed 42 -f har -o out.har

Config file (YAML or JSON) ​

yaml
seed: 42                 # deterministic seed
count: 10                # samples per base spec/template
specs:                   # explicit request specs (optional)
  - method: GET
    url: https://api.example.com/users
    headers:
      Accept: application/json
templates:               # reference built-in templates (optional)
  - name: getjson
    url: https://api.example.com/users
  - name: login
    url: https://api.example.com/login
    method: POST         # override method
transforms:              # enable transforms
  - server_ip
  - user_agent
  - path
  - query_noise
  - status
  - timings
  - index
export:
  format: curl           # default output format

Batch execution flow ​

mermaid
flowchart TB
    Cfg["Config YAML/JSON"] --> Load["LoadConfig"]
    Load --> Res["ResolveSpecs"]
    Res --> Specs["[]RequestSpec"]
    Specs --> Loop{"for each base spec"}
    Loop --> Gen["NewGenerator(seed)"]
    Gen --> GS["GenerateSpecs(base, count, transforms)"]
    GS --> Batch["[]RequestSpec (derived)"]
    Batch --> All["merge all derived specs"]
    All --> Build["Generate(all)"]
    Build --> Har["*har.Har"]
    Har --> Export["Export"]
    Export --> Out["stdout / file"]

    style Cfg fill:#e1f5ff
    style Out fill:#e8f5e9

CLI overrides ​

  • -n overrides count in config
  • --seed overrides seed
  • -f overrides export.format

Example configs ​

See examples/config/batch.yaml in the repo.

Released under the MIT License.