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.
apiproxy Create Jun 13, 2017 Add sample proxy bundle for changing the target endpoint with the hel… Apr 29, 2013

Rerouting a target URL

Sample use case

Rewrite a target URL dynamically on Apigee Edge.


This sample uses these policies:

  • alt text Extract Variables: To extract part of the request path into a variable.
  • alt text JavaScript: Rewrites the target URL.


This sample API proxy illustrates how to change the target endpoint URL using a JavaScript policy to set the target.url flow variable. This variable holds the complete URL for the back-end target endpoint, including any query parameters.

  1. Deploy the proxy.

  2. Send this request to Apigee Edge.

    Note: The proxy is configured with a base path of /zip. The incoming request must contain that base path or the request will not be processed. Tip: Take a look at the apiproxy/proxies/default.xml to see where this base path is configured.


  3. An Extract Variables policy extracts the part of the path that comes after the /zip base path.

  4. The policy stores the value of the zip code in a flow variable called This value is specific to the back-end API. It identifies the locale for which to return geographical data. Here is the policy XML:

    <ExtractVariables name="extractZip">
            <Pattern ignoreCase="true">/{zip}</Pattern>
  5. A JavaScript policy rewrites the target URL by setting the target.url flow variable. This expression also appends the value to the query parameter address.

    context.setVariable("target.url", ""+context.getVariable(""));

  6. Finally, the newly formed target request is sent to the backend target, the Google maps API, and the geographical information for the specified zip code is returned.

Set up, deploy, invoke

See the main project README file for information about setting up, deploying, and invoking sample proxies.


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

alt text

More information

Policies used in this sample

Related information

Ask the community

alt text

Copyright © 2017 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.