—Rate this article—
 

Using the apigee-access module

The apigee-access module lets you access API proxy flow variables and caches from within Node.js application code. 

Obtaining apigee-access

The apigee-access module is integrated into the Apigee Edge platform. When you deploy Node.js code to Edge, this module is available to you. You simply need to require it in any Node.js code that you deploy. For example:

var access=require('apigee-access');

You can also download apigee-access for local development and testing. The apigee-access packaged module is available through npmjs.org

Accessing flow variables

When you deploy a Node.js application to Edge, you can access any of the supported "out-of-the-box" flow variables, flow variables created by policies, and any flow variables that you create yourself from within your Node.js code. Flow variables are created and exist within the context of an API proxy running on Edge. For detailed information, see Accessing flow variables in Node.js.

Accessing the cache

The apigee-access module lets you access the Apigee Edge distributed cache from your Node.js code. For detailed information, see Accessing the cache in Node.js.

Using the quota service

The apigee-access module lets you access the Apigee Edge quota service from your Node.js code. For detailed information, see Accessing the quota service in Node.js.

Using the secure store service

The apigee-access module lets you store sensitive data, such as passwords for backend services, in an encrypted format on Apigee Edge. For detailed information, see Using the secure store.

Running in local mode vs deployed mode

To support local development and testing, the apigee-access module works in a "local mode" with no dependencies on Apigee Edge; however, when the module is used with an API proxy that is deployed to Edge, the "local" functionality is replaced by native Edge functionality. For example, the full compliment of flow variables are accessible in deployed mode, while only a small subset are available when you run the Node.js application locally. For a list of these local-mode variables, see "Running in local mode", below.

Determining the mode in which the module is running

To determine which mode you are running apigee-access in:

var apigee = require('apigee-access') 
console.log('The deployment mode is ' + apigee.getMode()); 

The return value of getMode() tells you whether or not the Node.js application is deployed to Apigee Edge or is running in standalone mode. The method returns one of these two string results:

  • apigee - The Node.js application is running on Apigee Edge and all functionality is supported.
  • standalone - The Node.js application is running outside the Apigee Edge environment, and the default functionality described at the top of the document takes effect.

Running in deployed mode

When deployed to Edge, variables set by policies are visible to apigee-access, and variables added or modified by this module's methods are visible to subsequent policies in the proxy flow.

You can find the link of supported variables in the Variables Reference. These variables, and any that you create with your own names, are visible to apigee-access. Note that some variables are read-only. They are identified in the Variables Reference.

Running in local mode

In "local mode," you are running your Node.js code outside the context of Apigee Edge. In this mode, most of the the pre-defined flow variables are not accessible within your Node.js code. This table shows the small subset of flow variables that are available. These variables are supported here in order to support local development and testing of Node.js applications for Apigee Edge.

Variable Read-Only Type Notes
client.received.start.time Yes String Time at which the request was received
client.received.end.time Yes String Time at which the request was received
client.received.start.timestamp Yes Integer Time at which the request was received
client.received.end.timestamp Yes Integer Time at which the request was received

Again, on the Apigee Edge platform, a much larger set of pre-defined variables is supported. Refer to the Apigee Edge Variables Reference for the complete list.

Missing a variable that you need for a test? Open a GitHub issue and we can add it, or send a pull request.

 

Help or comments?

  • Something's not working: See Apigee Support
  • Something's wrong with the docs: Click Send Feedback in the lower right.
    (Incorrect? Unclear? Broken link? Typo?)