Skip to content

formats / transforms ​

formats — list supported export formats ​

bash
request-mock formats
# {"formats":["curl","wget","python","postman","xml","yaml","har","json","jsonl","csv","markdown","html","text"],"ok":true}

request-mock formats --raw
# curl
# wget
# python
# ...

Format table ​

FormatDescriptionMulti-entry
curlcurl command(s)one per entry
wgetwget command(s)one per entry
pythonPython requests codeone per entry
postmanPostman collection v2.1single collection
xmlHAR XMLsingle doc
yamlHAR YAMLsingle doc
har / jsonHAR JSONsingle doc
jsonlJSON Lines (one entry per line)one per entry
csvTabular CSV (method,url,status,...)one per entry
markdownHuman-readable markdown tablesingle doc
htmlHTML tablesingle doc
textPlain text summarysingle doc

transforms — list built-in transforms ​

bash
request-mock transforms
# {"ok":true,"transforms":["body_noise","connection","header","host","index","path","port","priority","query_noise","resource_type","resp_cookie","seq_status","server_ip","status","timings","user_agent"]}

request-mock transforms --raw
# body_noise
# connection
# ...

Transform descriptions ​

NameMutatesDescription
server_ipServerIPRandom IPv4 address
user_agentHeaders["User-Agent"]Random UA from pool
pathURL pathRandom suffix segment
query_noiseQuery paramsAdd random noise params
statusResponseStatusRandom HTTP status (200/4xx/5xx)
timingsTimingsRandom timing values
indexURLAppend /_idx=<i> query param
portURL portReplace port with random from pool
hostURL hostRandom subdomain prefix
resp_cookieResponseCookiesRandom response cookie
headerHeadersRandom request header
body_noisePostTextInject noise into JSON body
seq_statusResponseStatusSequential status codes (200→201→...→500→loop)
priorityPriorityRandom Chrome priority
resource_typeResourceTypeRandom Chrome resource type
connectionConnectionRandom connection ID

Transform pipeline ​

mermaid
flowchart LR
    Base["Base spec"] --> T1["server_ip"]
    T1 --> T2["user_agent"]
    T2 --> T3["path"]
    T3 --> T4["query_noise"]
    T4 --> T5["status"]
    T5 --> T6["timings"]
    T6 --> T7["index"]
    T7 --> Out["Derived spec"]

    style Base fill:#e1f5ff
    style Out fill:#e8f5e9

Transforms are applied in the order specified by --transform. If no --transform is given, the default set is used (defined in mock.DefaultTransforms). Pass --transform none to disable all transforms.

Custom transforms (SDK) ​

In Go, implement the mock.Transform function signature:

go
type Transform func(spec *RequestSpec, index int, r *rand.Rand)

func MyTransform(spec *RequestSpec, i int, r *rand.Rand) {
    spec.Headers["X-Custom"] = fmt.Sprintf("val-%d", r.Intn(1000))
}

specs := g.GenerateSpecs(base, 100, MyTransform, mock.RandomServerIP)

Released under the MIT License.