Skip to content

Responses

The response object of a stub describes what is served once the request pattern matches.

"response": {
"status": 201,
"statusMessage": "Created",
"headers": { "Content-Type": "application/json" },
"jsonBody": { "id": 1, "status": "created" }
}

Status and headers

FieldNotes
statusHTTP status code
statusMessageServed as the HTTP reason phrase on the wire
headersSingle- or multi-value

Body fields

Three fields can carry a body. If more than one is present, they are applied in this order:

OrderFieldType
1bodystring
2jsonBodyobject
3base64Bodybase64 string

body wins over jsonBody, and jsonBody wins over base64Body. Set exactly one to avoid ambiguity.

Templating

Add "transformers": ["response-template"] to a response to make its body and headers Handlebars templates. To enable it for every stub on the host, start the server with --global-response-templating.

"response": {
"status": 200,
"transformers": ["response-template"],
"jsonBody": { "echo": "{{jsonPath request.body '$.name'}}" }
}

See templating for the model and template helpers for the full helper reference.

Behaviour fields

These also live on response and each has its own page.

FieldPage
fixedDelayMillisecondsdelays and faults
delayDistributiondelays and faults
faultdelays and faults
proxyBaseUrlproxying
additionalProxyRequestHeadersproxying
proxyUrlPrefixToRemoveproxying

Compression

A response is gzipped when the request carries Accept-Encoding: gzip, regardless of the response content type. There is no per-content-type exclusion list.

Output shape quirks

Some rendered output is formatted in ways that look inconsistent on their own. These shapes are preserved deliberately, because WireMock produces them and differential parity is the definition of correct here.

CaseRendered as
jsonPath result that is an objectJackson-pretty (indented)
jsonPath result that is a top-level arrayCompact
toJson output containing arraysSpaced