This page applies to Apigee and Apigee hybrid.
View Apigee Edge documentation.
You can add code in procedural languages such as JavaScript, Java, and Python, then call out to that code from other parts of an API proxy. Support for procedural code is designed to make it easier for you to implement complex handling of flow variables, faults, and request and response bodies.
With procedural code, you can:
- Create or manipulate complex body values, such as request and response values.
- Rewrite URLs, such as to mask a target endpoint URL.
- Add other logic not available with included policies.
How it works
You use a policy specific to the language in order to make calls from a proxy flow to your included code. For each of the supported languages, Apigee includes a separate policy: JavaScript policy, JavaCallout policy, and PythonScript policy.
The following describes, at a high level, one way this works. Be sure to see the policy references for more details.
- In a separate file, write the code you're going to use.
- In your code, put the result of the code's processing into an Apigee flow variable.
You'll retrieve the variable value elsewhere in your API proxy. For more about flow variables, see Managing proxy state with flow variables.
- Add your file (or JAR) as a resource file to your API proxy.
For more about resource files, see Resource files.
- Add the policy corresponding to the language you're using.
Configure the policy to make a call to your code from the desired place in your API proxy's flow.
- Use a policy to retrieve the code's value from the flow variable.
Limitations
The Apigee security model does not permit system calls such as network I/O, filesystem read/writes, current user info, process list, and CPU/memory utilization. Although some such calls may be functional, they are unsupported and liable to be actively disabled at any time. For forward compatibility, you should avoid making such calls in your code.
Other limitations may exist for each supported language, as described in the language's corresponding policy reference.
Supported languages
JavaScript
Support for JavaScript includes a full object model for handling variables and values specific to an API proxy. For more, see JavaScript object model.
For policy reference information and examples, see JavaScript policy.
Java
Use the Java Callout policy to make calls to Java code from your proxy's flow. The policy reference topic includes examples.
Python
Use the Python Script policy to call out to Python code.