File read/write in Apigee Edge

Hi All,

Please let me know if it is possible to perform file read/write in Apigee Edge?

1 4 1,278
4 REPLIES 4

@GargiTalukdar , Can you please add more context to same ? Are you talking about an API that will read write data to external servers / Are you talking about storing files in Apigee Edge ? Are you talking about Node.JS in Apigee Edge with ability to read / write to files etc ? I believe above questions is too broad, adding more details will sure help to get responses. Thank you 🙂

Yes @Anil Sagar @ Google .

Is there any read option of plain text or even json file that I can store some params/property values and import from policy/s but JS policy?

Congratulations for resuscitating a question from almost 4 years ago!

Is there any read option of plain text or even json file that I can store some params/property values and import from policy/s but JS policy?

I'm sure I don't understand the question fully, but... depending on what you mean by "file", there are several ways to read values from within an API proxy.

There is no way to store a plain "file" in the Apigee service and read THAT. However, you can embed a file within your API Proxy and then your API Proxy will have access to its contents .

One way is to use a JS policy like so:

<Javascript name='JS-Settings' timeLimit='200' >
  <IncludeURL>jsc://settings.js</IncludeURL> 
  <ResourceURL>jsc://readSettings.js</ResourceURL>
</Javascript>

The settings.js file can just define a global variable. like this:

var settings = {
      client_id : '71783652426-qm.apps.googleusercontent.com',
      client_secret : '6kruexfj9_MsJWwrEZml99q'
    };

And then from within the readSettings.js file, your code can read that global variable (global in the JS scope) and then set context variables appropriately. Maybe like this:

Object.keys(settings).forEach(function(key){
  context.setVariable('settings_' + key, settings[key]);
});

Subsequent policies would then have access to those context variables. You're not really "reading" the file explicitly. Instead the JS step "reads" the file implicitly and your JS code then has access to the information in the file. If you want to update the settings, update the settings.js file and re-deploy the proxy.

Another way to sort of "read" a file is to create a file with the contents of a KVM value, and then at deployment time, load the contents of the file into a KVM, using the Apigee Administrative API.

Another way is to simply store all the settings into an AssignMessage policy that contains the values:

<AssignMessage name='AM-Settings'>
  <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
  <AssignVariable>
    <Name>timeFormatString1</Name>
    <Value>yyyyMMdd HH:mm:ss.SSS</Value>
  </AssignVariable>
  <AssignVariable>
    <Name>client_id</Name>
    <Value>71783652426-qm.apps.googleusercontent.com</Value>
  </AssignVariable>
  ...

Another way is to use a remote service to "host" the settings file, and use a ServiceCallout to GET that URL to retrieve settings.

Any of these would work; which approach you choose depends on your other requirements and preferences.

To answer the original question, though, there is no way to "write" an arbitrary file from within Apigee Edge. All of the above works for reading only.