I’m creating a JS callout policy that will invoke code in a JavaScript file. Let’s call it A.js.
How do I make a call to a function doSomething() in another JavaScript file called B.js?
Is there a way to ‘include’ or ‘import’ or ‘require’ B.js in A.Js?
Appreciate the help.
2 Likes
Yes, there is.
When you define your Javascript policy, include B.JS in the IncludeURL as shown below
<Javascript async="false" continueOnError="false" enabled="true" timeLimit="100"
name="your-javascript-name">
<DisplayName>JavaScript 1</DisplayName>
<ResourceURL>jsc://A.js</ResourceURL>
<IncludeURL>jsc://B.js</IncludeURL>
</Javascript>
The above would have the same semantics as if you “imported” B.js into A.js
Keep in mind that B.js needs to exist next to A.js or it needs to be uploaded as an organization level resource.
4 Likes
Thank you. I just figured it out and was posting the answer. You beat me to it. Appreciate the help.
See also, this article regarding structuring JavaScript modules in Apigee Edge.
Thanks. This is very useful.