Using the apigee-access module
apigee-access module lets you access API proxy flow variables and caches from within Node.js application code.
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:
You can also download
apigee-access for local development and testing. The
apigee-access packaged module is available through npmjs.org.
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.
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.
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.
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.
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 access = require('apigee-access') console.log('The deployment mode is ' + access.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.
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.
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.
|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.