Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Using third-party JavaScript libraries

Sample use case

How to use include third-party libraries in JavaScript policies.


This sample uses these policies:

  • alt text JavaScript: Includes a main script and several dependencies.
  • alt text Assign Message: Sets the encoded credentials into a response header.


In a JavaScript policy, you can load JavaScript files as dependencies to the main JavaScript file. Here's how the JavaScript policy looks in this sample, where encodeAuthHeader.js is the main JavaScript file.

    <Javascript timeLimit="200" name="EncodeAuthHeader">

The included scripts are evaluated in the order in which they are listed in the policy. Any of the dependent code can use the objects, methods, and properties of the Apigee Edge JavaScript object model.

This demo uses code from the third-party CryptoJS module to do base64 encoding on the user name and password presented in the request.

Note that Apigee has a Basic Authentication policy that also performs base64 encoding. This sample proxy is for third-party library Javascript demonstration purposes.

Set up, deploy, invoke

To deploy, run $ sh

To test, run $ sh

If you open take a look at the cURL call:

curl -i "https://$org-$env.$api_domain/base64encoder?username=MyUserName&password=MyPassword"

It just passes arbitrary username and password strings. You can change them if you want, but they aren't actually validated by this sample. The JavaScript policy grabs whatever values are presented and base64 encodes them.


An Assign Message policy echoes the encoded value back to the client as a custom HTTP header.

    HTTP/1.1 200 OK
    User-Agent: curl/7.37.1
    Accept: */*
    X-Encoded-Credentials: Basic TXlVc2VyTmFtZTpNeVBhc3N3b3Jk
    Content-Length: 0
    Connection: keep-alive


This screen shot from the Apigee Edge trace tool shows the placement of the policies used in this sample.

alt text

More information

Policy used in this sample

Ask the community

alt text

Copyright © 2015 Apigee Corporation

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

You can’t perform that action at this time.