Transform Response Body

This example policy shows how to use response.json() to read the outgoing response as a JSON object. The object can then be modified as appropriate. It is then converted back to a string and a new Response is returned in the policy with the new body.

If the incoming response body is not JSON, you can use response.text() or response.blob() to access the contents as raw text or a blob.

Configuration#

{
  "name": "transform-body-outbound",
  "policyType": "custom-code-outbound",
  "handler": {
    "export": "default",
    "module": "$import(./modules/transform-body-outbound)"
  }
}

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 be transform-body-outbound.
  • handler/export The name of the exported type. Value should be default.
  • handler/module the module containing the policy. Value should be $import(./modules/YOUR_MODULE).

Was this article helpful?

Do you have any questions?Contact us
Check out ourproduct changelog