Incorporating procedural code

You're viewing Apigee Edge documentation.
Go to the Apigee X documentation.
info

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 Edge includes a separate policy: JavaScript policy, Java Callout policy, and Python Script policy.

The following describes, at a high level, one way this works. Be sure to see the policy references for more details.

  1. In a separate file, write the code you're going to use.
  2. In your code, put the result of the code's processing into an Apigee Edge 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.

  3. Add your file (or JAR) as a resource file to your API proxy.

    For more about resource files, see Resource files.

  4. 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.

  5. Use a policy to retrieve the code's value from the flow variable.

Limitations

The Apigee Edge 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 and Programming API proxies with JavaScript. For sample code, search Samples list for those with JavaScript included.

Java

Use the Java Callout policy to make calls to Java code from your proxy's flow. The policy reference topic includes examples.

You might also be interested in the following topics:

For sample code, search Samples list for those with Java included.

Python

Use the Python Script policy to call out to Python code.

For sample code, search Samples list for those with Python included.