Reuse functions in JS policies

Not applicable

We're currently looking for a good way to define reusable functions in separate JS policies. First idea is to use context.session.foo = function () { ... }. It also seems we could do context.fn = { foo: function () { ... } }; or similar. Is their any best practice for this? Or any caveats? Do closures "simply work" accross policies?

1 3 264
3 REPLIES 3

adas
New Member

JavaScript policy allows including other javascript files in Apigee. You can create an org/env level JavaScript resource and use that in other JavaScript policies with the includeURL directive. There are examples, available in the docs. I can send you some samples demonstrating the use of it.

Yes, I know, that's why I'm asking how to best define functions reusable across policies. Do policies in the same API call share a global namespace? Do closures work? etc.

Not applicable

Looks like context.fn = ... does not work. We're using context.session.fn for now