Was this helpful?

Apigee provides a range of out-of-the-box policy capabilities that address common API management requirements. However, there are some cases where your API requires custom behavior that is not covered by Apigee's standard policy palette. In these cases, Apigee exposes scripting interfaces to ease the task of implementing custom behaviors in the proxied API message flow. One approach is to attach your own JavaScript to an API flow, which the API Platform then executes at runtime.

A JavaScript policy contains no actual code. Instead, a JavaScript policy references a JavaScript 'resource' and defines the Step in the API flow where the JavaScript executes. You can upload your JavaScript through the Management UI proxy editor, or you can include it in the /resources directory in API proxies that you develop locally.

For instructions, policy samples, and JavaScript samples, see Use JavaScript to customize an API.

For instructions on building and deploying full-fledged JavaScript apps for the API Platform, see the Building a composite service using JavaScript.

Configuring a JavaScript policy

Configure the JavaScript policy using the following elements.

Field Name Description
Display Name The name attribute of the JavaScript policy
Execution Time Limit Specifies the maximum time (in milliseconds) that the script is permitted to execute. For free trial accounts, execution time is limited to 200 ms.
Resource (JavaScript file) Specifies the JavaScript resource (file), stored under /apiproxy/resources/jsc, that implements the Building a composite service using JavaScript

Policy schema

Each policy must conform to a policy schema. All policy constructs such as elements and attributes mentioned above are defined in a schema. To download the schema, click here.

Example - JavaScript policy

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Javascript timeLimit="200" enabled="true" continueOnError="false" async="false" name="MyJSPolicy">
   <ResourceURL>jsc://MyJavaScript</ResourceURL>
   <IncludeURL>jsc://MyJavaScript</IncludeURL>
</Javascript>