Skip to content

Export Formats ​

The request-mock CLI and SDK support 13 export formats for generated HAR data.

Format Table ​

FormatCLI FlagDescriptionMulti-entry
curlcurlcurl command(s)One per entry
wgetwgetwget command(s)One per entry
PythonpythonPython requests codeOne per entry
PostmanpostmanPostman collection v2.1Single collection
XMLxmlHAR XML representationSingle document
YAMLyamlHAR YAML representationSingle document
HARharHAR JSON (standard format)Single document
JSONjsonHAR JSON aliasSingle document
JSON LinesjsonlOne JSON entry per lineOne per line
CSVcsvTabular CSV (method, URL, status, ...)One per row
MarkdownmarkdownHuman-readable markdown tableSingle document
HTMLhtmlHTML tableSingle document
TexttextPlain text summarySingle document

CLI Usage ​

Default output (JSON envelope) ​

bash
request-mock generate -X GET -u https://api.example.com/users -f har

Raw output ​

bash
request-mock generate -X GET -u https://api.example.com/users -f curl --raw

Export to file ​

bash
request-mock generate -X GET -u https://api.example.com/users -f postman -o collection.json

Re-export an existing HAR ​

bash
request-mock export --input out.har -f curl --raw
request-mock export --input out.har -f csv -o output.csv

SDK Usage ​

go
// Export as string
curl, _ := mock.Export(h, mock.FormatCurl)

// Export as bytes with indent
data, _ := mock.ExportBytes(h, mock.FormatJSON, mock.WithExportIndent(2))

// Export to file
mock.ExportToFile(h, mock.FormatCSV, "output.csv")

// MustExport (panics on error)
out := mock.MustExport(h, mock.FormatCurl)

Format Constants ​

go
mock.FormatCurl       // "curl"
mock.FormatWget       // "wget"
mock.FormatPython     // "python"
mock.FormatPostman    // "postman"
mock.FormatXML        // "xml"
mock.FormatYAML       // "yaml"
mock.FormatHAR        // "har"
mock.FormatJSON       // "json"
mock.FormatJSONLines  // "jsonl"
mock.FormatCSV        // "csv"
mock.FormatMarkdown   // "markdown"
mock.FormatHTML       // "html"
mock.FormatText       // "text"

Implementation ​

Each format is dispatched in mock.Export() via a switch statement that calls the corresponding method on *har.Har from the har-skills library:

  • curl → ToCurl()
  • wget → ToWget()
  • python → ToPythonRequests()
  • postman → ToPostmanCollection()
  • xml → ToXML()
  • yaml → ToYAML()
  • har / json → ToJSON()
  • jsonl → ToJSONLines()
  • csv, markdown, html, text → Convert(format, opts)

Released under the MIT License.