Puedes agregar código en lenguajes de procedimiento como JavaScript, Java y Python, y luego llamar a ese código desde otras partes de un proxy de API. La asistencia para el código de procedimientos está diseñada para que sea más fácil implementar un control complejo de variables de flujo, fallas y cuerpos de solicitud y respuesta.
Con el código de procedimiento, puedes hacer lo siguiente:
Crear o manipular valores de cuerpo complejos, como valores de solicitud y respuesta
Volver a escribir las URL, como para enmascarar una URL de extremo de destino
Agregar otra lógica que no esté disponible con las políticas incluidas
Agrega el archivo (o JAR) como un archivo de recursos al proxy de la API.
Para obtener más información sobre los archivos de recursos, consulta Archivos de recursos.
Agrega la política correspondiente al lenguaje que usas.
Configura la política para realizar una llamada a tu código desde el lugar deseado en el flujo del proxy de API.
Usa una política para recuperar el valor del código de la variable de flujo.
Limitaciones
El modelo de seguridad de Apigee no permite llamadas al sistema, como E/S de red, lectura y escritura del sistema de archivos, información actual del usuario, lista de procesos y uso de CPU o memoria. Aunque algunas de estas llamadas pueden ser funcionales, no son compatibles y son responsables de inhabilitarse de forma activa en cualquier momento. Para garantizar la compatibilidad con versiones futuras, debes evitar realizar este tipo de llamadas en tu código.
Existen otras limitaciones para cada lenguaje admitido, como se describe en la referencia de la política correspondiente del lenguaje.
Idiomas admitidos
JavaScript
La compatibilidad con JavaScript incluye un modelo de objetos completo para controlar variables y valores específicos de un proxy de API. Para obtener más información, consulta el modelo de objetos de JavaScript.
Para obtener información de referencia de la política y ejemplos, consulta la política de JavaScript.
Java
Usa la política de texto destacado de Java para realizar llamadas al código de Java desde el flujo de tu proxy. En el tema de referencia de la política, se incluyen ejemplos.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-09-04 (UTC)"],[[["\u003cp\u003eThis content covers how to use procedural code (JavaScript, Java, and Python) within Apigee and Apigee hybrid API proxies to manage flow variables, faults, and request/response bodies.\u003c/p\u003e\n"],["\u003cp\u003eApigee provides specific policies (JavaScript, JavaCallout, and PythonScript) to call out to your procedural code, which can be used to implement complex logic or rewrite URLs.\u003c/p\u003e\n"],["\u003cp\u003eProcedural code allows for the manipulation of complex body values, and logic not available through built-in policies, with results stored in flow variables for retrieval elsewhere in the API proxy.\u003c/p\u003e\n"],["\u003cp\u003eTo use procedural code, you write the code in a separate file, add it as a resource file to your API proxy, configure the relevant language policy to call the code, and retrieve the results using flow variables.\u003c/p\u003e\n"],["\u003cp\u003eThe security model in Apigee restricts certain system calls in procedural code, such as network I/O and file system operations, which should be avoided for forward compatibility.\u003c/p\u003e\n"]]],[],null,["# Incorporating procedural code\n\n*This page\napplies to **Apigee** and **Apigee hybrid**.*\n\n\n*View [Apigee Edge](https://docs.apigee.com/api-platform/get-started/what-apigee-edge) documentation.*\n\nYou can add code in procedural languages such as JavaScript, Java, and Python, then call out\nto that code from other parts of an API proxy. Support for procedural code is designed to make it\neasier for you to implement complex handling of flow variables, faults, and request and response\nbodies.\n\nWith procedural code, you can:\n\n- Create or manipulate complex body values, such as request and response values.\n- Rewrite URLs, such as to mask a target endpoint URL.\n- Add other logic not available with included policies.\n\nHow it works\n------------\n\nYou use a policy specific to the language in order to make calls from a proxy flow to your\nincluded code. For each of the supported languages, Apigee includes a separate policy:\n[JavaScript policy](/apigee/docs/api-platform/reference/policies/javascript-policy), [JavaCallout policy](/apigee/docs/api-platform/reference/policies/java-callout-policy), and [PythonScript policy](/apigee/docs/api-platform/reference/policies/python-script-policy).\n\nThe following describes, at a high level, one way this works. Be sure to see the policy\nreferences for more details.\n\n1. In a separate file, write the code you're going to use.\n2. 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\n variables, see [Managing\n proxy state with flow variables](/apigee/docs/api-platform/fundamentals/introduction-flow-variables).\n\n3. Add your file (or JAR) as a resource file to your API proxy. For more about resource files, see [Resource files](/apigee/docs/api-platform/develop/resource-files).\n\n4. 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\n proxy's flow.\n\n5. Use a policy to retrieve the code's value from the flow variable.\n\nLimitations\n-----------\n\nThe Apigee security model does not permit system calls such as network I/O, filesystem\nread/writes, current user info, process list, and CPU/memory utilization. Although some such\ncalls may be functional, they are unsupported and liable to be actively disabled at any time. For\nforward compatibility, you should avoid making such calls in your code.\n\nOther limitations may exist for each supported language, as described in the language's\ncorresponding policy reference.\n\nSupported languages\n-------------------\n\n### JavaScript\n\nSupport for JavaScript includes a full object model for handling variables and values specific\nto an API proxy. For more, see [JavaScript object model](/apigee/docs/api-platform/reference/javascript-object-model).\n\nFor policy reference information and examples, see [JavaScript policy](/apigee/docs/api-platform/reference/policies/javascript-policy).\n\n### Java\n\nUse the [JavaCallout\npolicy](/apigee/docs/api-platform/reference/policies/java-callout-policy) to make calls to Java code from your proxy's flow. The policy reference topic includes\nexamples.\n\n### Python\n\nUse the [Python Script\npolicy](/apigee/docs/api-platform/reference/policies/python-script-policy) to call out to Python code."]]