Custom Policies as templates

Not applicable

Once I create a custom policy for an api proxy, Is there a way to reuse the custom policy in some other api proxy, such as by adding the custom policy into the policy list when you click the Add Step button?

4 9 975
9 REPLIES 9

guy_hagemans
Participant III

I assume with a 'custom policy 'you mean an 'Extension Policy'. There is no easy way to reuse this logic. What you could do is:

  1. Copy Paste the code
  2. Download the proxy revision and copy the policy source into your proxy. For this, please note that each policy apart from copying it into the /policies folder, it should also be entered in the root's .xml file.
  3. Create a microservice. Although calling API's from other APIs can become spaghetti.

1 and 2 are a manual process that is prone to human error. 3 will use up more of your API quota. I'd recommend looking at https://github.com/apigee/proxy-dependency-maven-plugin, which is essentially an automated copy and paste as you suggested 🙂

Please see the Dependency Maven plugin: https://github.com/apigee/proxy-dependency-maven-plugin

You can share resources between proxies. It's not quite what you're describing, but perhaps it is enough. Refer to documentation here on org and environment resources:

http://apigee.com/docs/api-services/content/resource-files

Gayan, we're considering that capability. We think it's interesting.

Thanks Dino. It will increase the usability of the API Proxy development env and avoid doing same manual steps over and over

@Dino

Just curious, I have almost the same requirement. ie. If I've a common utility (say, jsc extension policy) that can be used across my org, what is the best practice recommendation for reuse other than copy/paste.

Not applicable

Other alternatives to reuse code are leveraging NPM, Git Subtrees, and Submodules. I'm more biased towards NPM as it's very easy to publish and download modules to/from. And you can store anything in them, not only JS, but XML, text, or binary files. You can find more info here. Then you can leverage a build tool such as Grunt to search and replace text, similar to the dependency plugin. Take a look at this API Proxy generator.

Not applicable

Hi, @Gayan Shyamal. I just came across your question, and I wonder if this article might be of interest to you.