- policyRef:
name: dataweave-request-filter-flex
config:
script: <string> // REQUIRED - DataWeave script
requiresPayload: <boolean> // OPTIONAL, default: false
DataWeave Request Filter Policy
Policy name |
DataWeave Request Filter |
Summary |
Filters requests by using a DataWeave script |
Category |
Transformation |
First Flex Gateway version available |
1.12 |
Returned Status Codes |
|
Summary
The DataWeave Request Filter policy evaluates a DataWeave script on the request, including headers and the body, to allow or block the message. The script returns an object with a Boolean success value. If success is false, the script can return a response object with statusCode, body, and headers. The gateway sends that as the immediate HTTP response to the client and stops processing. If success is true, the message continues.
Result format:
-
Success:
{ "success": true } -
Error:
{ "success": false, "response": { "body": "…", "headers": {}, "statusCode": 400 } }
Configure Policy Parameters
Flex Gateway Local Mode
| Parameter | Required | Default Value | Description |
|---|---|---|---|
|
Required |
— |
A DataWeave script that returns an object with a boolean |
|
Optional |
false |
If true, the script receives the message body in the |
Resource Configuration Example
policies:
- policyRef:
name: dataweave-request-filter-flex
config:
script: |
%dw 2.0
output application/java
---
if (attributes.headers["x-api-key"] != null) { success: true }
else { success: false, response: { statusCode: 401, body: "Missing API key", headers: {} } }
requiresPayload: false
Managed Flex Gateway and Flex Gateway Connected Mode
When you apply the policy to your API instance from the UI, the following parameters are displayed:
| Parameter | Description |
|---|---|
Policy type |
DataWeave Request Filter |
Script |
The DataWeave script that returns a success or error result |
Requires payload |
Whether the script requires the message body |
Method & Resource conditions |
The option to add configurations to only a select few or all methods and resources of the API |



