You can use the Mock policy to create mock responses when a consumer calls one of your services. This means you do not have to provide a functional backend as soon as you create your API, giving you more time to think about your API contract.
You can think of the policy as a contract-first approach — you are able to create a fully-functional API without needing to write a single line of code to handle consumer calls.
Internally, this policy replaces the default HTTP invoker with a mock invoker. There are no more HTTP calls between the gateway and a remote service or backend.
Note: The Mock policy will not cause the other policies to be skipped, regardless of its location in the flow.
When defining the response body content, you can use Expression Language to provide a dynamic mock response.
The response body content and header values support Gravitee Expression Language (EL). This allows you to create dynamic mock responses based on request context.
Available EL variables include:
{#request.paths[n]}— Access path segments{#request.headers['X-Custom']}— Access request headers{#properties['key']}— Access API properties
{
"id": "{#request.paths[3]}",
"firstname": "{#properties['firstname_' + #request.paths[3]]}",
"lastname": "{#properties['lastname_' + #request.paths[3]]}",
"age": {(T(java.lang.Math).random() * 60).intValue()},
"createdAt": {(new java.util.Date()).getTime()}
}<user id="{#request.paths[3]}">
<firstname>{#properties['firstname_' + #request.paths[3]]}</firstname>
<lastname>{#properties['lastname_' + #request.paths[3]]}</lastname>
<age>{(T(java.lang.Math).random() * 60).intValue()}</age>
<createdAt>{(new java.util.Date()).getTime()}</createdAt>
</user>You don't need to provide the Content-Type header. The Mock policy automatically detects the content type of the response body (JSON, XML, or plain text).
The mock policy can be applied to the following API types and flow phases.
PROXYMCP PROXY
- Request
Strikethrough text indicates that a version is deprecated.
| Plugin version | APIM | Java version |
|---|---|---|
| 2.0.0 and after | 4.11 and after | 21 |
| 1.14.0 to 1.15.x | 4.1.24 and after | 17 |
| Up to 1.13.5 | All supported versions | 11 |
Name json name |
Type constraint |
Mandatory | Description |
|---|---|---|---|
Response bodycontent |
string | The body content of the mock response. Supports Expression Language for dynamic values. | |
Headersheaders |
array | Custom HTTP headers to include in the mock response. Header values support Expression Language. See "Headers" section. |
|
HTTP Status Codestatus |
enum (string) | ✅ | HTTP status code returned to the consumer in the mock response. Values: 100 101 102 200 201 202 203 204 205 206 207 300 301 302 303 304 305 307 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 422 423 424 429 500 501 502 503 504 505 507 |
Name json name |
Type constraint |
Mandatory | Description |
|---|---|---|---|
Namename |
string | Name of the header | |
Valuevalue |
string | Value of the header (support EL) |
Mock a JSON response with Expression Language
{
"api": {
"definitionVersion": "V4",
"type": "PROXY",
"name": "Mock Policy example API",
"flows": [
{
"name": "Common Flow",
"enabled": true,
"selectors": [
{
"type": "HTTP",
"path": "/",
"pathOperator": "STARTS_WITH"
}
],
"request": [
{
"name": "Mock Policy",
"enabled": true,
"policy": "mock",
"configuration":
{
"status": "200",
"headers": [
{
"name": "Content-Type",
"value": "application/json"
},
{
"name": "Server",
"value": "Gravitee.io"
}
],
"content": "{\"id\": \"{#request.paths[3]}\", \"name\": \"{#properties['name']}\"}"
}
}
]
}
]
}
}
Mock a JSON response on MCP Proxy API
{
"api": {
"definitionVersion": "V4",
"type": "MCP_PROXY",
"name": "Mock Policy example API",
"flows": [
{
"name": "All plans flow",
"enabled": true,
"selectors": [
{
"type": "MCP",
"methods" : []
}
],
"request": [
{
"name": "Mock Policy",
"enabled": true,
"policy": "mock",
"configuration":
{
"status": "200",
"headers": [
{
"name": "Content-Type",
"value": "application/json"
},
{
"name": "Server",
"value": "Gravitee.io"
}
],
"content": "{\"id\": \"{#request.paths[3]}\", \"name\": \"{#properties['name']}\"}"
}
}
]
}
]
}
}
2.0.0 (2026-02-13)
- rewrite for V4 engine (bd47642)
- compatible with APIM >= 4.11
1.15.0 (2025-12-11)
- enable for MCP Proxy API (d4c0957)
1.15.0-alpha.1 (2025-11-07)
- enable for MCP Proxy API (c58383b)
1.14.2 (2025-07-06)
- ensure example values with 'string' + 'date-time' format are handled correctly (1c31dea)
1.14.1 (2025-03-11)
- rework response example extractor from schema (9915115)
1.14.0 (2024-09-18)
- support mock policy on v4 proxy API request phase (8251445)
- update schema-form for v4 policy studio (ce1db74)
1.13.5 (2023-10-31)
- jsonSchema - config code editor mode for new policy studio display (d13ba38)
1.13.4 (2023-09-28)
- handle array in response (1f97ed8)
1.13.3 (2023-09-27)
- handle no components in OpenAPI descriptor (49904ac)
1.13.2 (2023-07-20)
- deps: bump dependency (6bcf31d)
1.13.1 (2023-07-20)
- update policy description (77dae49)
1.13.0 (2022-01-21)
- headers: Internal rework and introduce HTTP Headers API (93f1afa), closes gravitee-io/issues#6772