Resource files

Many policy types defined by Apigee Edge rely on resources. Resources are the files that implement the code or configuration to be executed by a policy when attached to an API proxy. In some cases, as with JavaScript and JavaCallout, a policy simply defines an attachment point in an API proxy where some code should execute. A JavaScript or JavaCallout policy is a pointer to a resource.

In the management UI, resources scoped to an API proxy are listed in the Scripts section of the Navigation pane.

These resources can be stored in any of three locations in an organization.

API proxy: When stored in an API proxy, resources are available only to that API proxy.

Environment: When stored in an environment (for example, test or prod), the resource is available to any API proxy deployed in the same environment.

Organization: When stored in an organization, the resource is available to any API proxy deployed in any environment.

In addition to storing resources at the proxy level, API Services also provides repositories for these resources at the organization and the environment level. By storing resources at the organization or the environment level, you enable reuse and sharing of code and configuration across the API proxies deployed in your organization and across different environments.

The example API calls in this topic use cURL. You can also use the SmartDocs management API reference topics to make the same calls. See the Resource files API.

Populating resource repositories

When updating an existing resource in a deployed API proxy, you must redeploy the API proxy after to ensure the resource changes are picked up. Newly added resources do not require API proxy redeployment.

Let's assume that you have a simple snippet of JavaScript that you need to make available to API proxies across your organization. The following sample JavaScript sets the HTTP request path to the value of the proxy.basepath variable. It's just one example of a resource that you might need to put in the repository.

request.setHeader("RequestPath", flow.getVariable("proxy.basepath"));

To create a resource, you call the POST method, submitting the body of the resource file, and identifying the resource's name and type as query parameters.

To make the JavaScript available to API proxies running in any environment in your organization:

You can also upload resources as files from your local machine as follows. It's important to use -F for the binary upload in cURL in order for the environment- and organization-scoped JavaScript files to be accessible by the JavaScript policy.

Resource name resolution

Apigee Edge resolves resource names from the most specific to the most general scope. Resource names are resolved "up the chain", from the API proxy level, to the environment level, to the organization level.

Let's say that you have populated the same resource in two different repositories — the organization and the environment: