import { Context, ExecutionContext, IPolicy, tryExecuteFieldValue, YapPolicy } from "@youngapp/yap";
description: 'The example-policy policy to set the message body for incoming and outgoing requests.',
scopes: ['inbound', 'outbound', 'on-error']
export class ExamplePolicy implements IPolicy {
* Use the example-policy policy to set the message body for incoming and outgoing requests.
* To access the message body you can use the context.request.body property
* or the context.response.body, depending on whether the policy is in the inbound or
* <example-policy>bJtrpFi1fO1JMCcwLx8uZyAg</example-policy>
public async apply(executionContext:ExecutionContext) {
const { policyElement, context, scope } = executionContext;
context.request.body = tryExecuteFieldValue(policyElement.elements[0].text, executionContext);
public validate(policyElement: any) {