Transform Request Body
This example policy shows how to use request.json()
to read the incoming
request as a JSON object. The object can then be modified as appropriate. It is
then converted back to a string and a new Request
is returned in the policy
with the new body.
If the incoming request body is not JSON, you can use request.text()
or
request.blob()
to access the contents as raw text or a
blob.
Configuration#
{
"name": "transform-body-inbound",
"policyType": "custom-code-inbound",
"handler": {
"export": "default",
"module": "$import(./modules/transform-body-inbound)"
}
}
Options#
name
the name of your policy instance. This is used as a reference in your routes.policyType
the identifier of the policy. This is used by the Zuplo UI. Value should betransform-body-inbound
.handler/export
The name of the exported type. Value should bedefault
.handler/module
the module containing the policy. Value should be$import(./modules/YOUR_MODULE)
.