Was this Helpful?

Apigee provides a set of samples on GitHub that you can download and run locally. For a list of samples, see Samples reference.

Prerequisites

The samples require you to have an account on http://enterprise.apigee.com. You can sign up for a trial account at http://accounts.apigee.com/accounts/sign_up.

For more information on creating accounts, see Creating an Apigee Edge account.

To use samples, you should also install Git and Python.

Git

The samples are located on GitHub. If you do not have Git installed, please refer to GitHub's git setup instructions. If you don't want to install Git, you can browse the files and download a ZIP from https://github.com/apigee/api-platform-samples.

Python

Python is required to run the Apigee deploy tool. Python is present in most Linux environments, on a Mac with XCode installed, on a Windows machine with Cygwin installed, and in many other places.

To obtain Python, please refer to the Python download page

Downloading the samples

To obtain the sample files, run:

$ git clone https://github.com/apigee/api-platform-samples.git

Importing and deploying the sample API proxies

Use the following procedure to import and deploy the samples:
  1. After you download the samples, go to the /setup directory.

    $ cd setup
  2. In the /setup directory, locate the file setenv.sh. Edit this file to set your organization, the email address associated with your username, and the environment (prod or test) where you want to deploy the API proxies.
     
  3. After you edit setenv.sh, run:

    $ sh deploy_all.sh
    This script deploys all API proxy samples to your organization. (The process takes 3-4 minutes.) Follow prompts to deploy API products, developers, and apps (which are used for OAuth).
     
  4. After the deploy script completes, navigate to the sample-proxies directory. In the directory sample-proxies, you will find one directory per sample proxy. In each directory is a README.md file with information about running the sample, and two scripts that help you as you make small changes to the samples, deploy, and then invoke the sample to see what effect you change had:
    • invoke.sh: Run this script to invoke the deployed version of the API proxy.
    • deploy.sh: Run this script to deploy the API proxy after you make any changes.

Invoking the sample API proxies

Each sample proxy has an associated shell script that can be used to invoke the API proxy after you deploy it.

From the /sample-proxies/{proxy_name} directory, run:

$ sh invoke.sh

This will invoke the proxy that is running in the test environment in your organization.

Troubleshooting

If you run into issue with the sample, see Troubleshooting.

Modifying and reusing the sample API proxies

Typical usage of the sample proxies is to modify, deploy, and invoke. This enables you to make small modifications, and then to see what effect they have on the response message.

If you need to modify a sample API proxy to point at a different backend service, modify the XML configuration file under:

/apiproxy/targets/{target_name}.xml

For example, to point the API key sample at your own backend service, locate this file:

/apikey/apiproxy/targets/default.xml

The default configuration points to http://weather.yahooapis.com/.

<TargetEndpoint name="default">
  <HTTPTargetConnection>
    <!-- This is where we define the target. For this sample we just use a simple URL. -->
    <URL>http://weather.yahooapis.com/</URL>
  </HTTPTargetConnection>
</TargetEndpoint>

If your backend service is available at http://api.myproject.com/, then you modify the configuration to look like the following:

<TargetEndpoint name="default">
  <HTTPTargetConnection>
    <!-- This is where we define the target. For this sample we just use a simple URL. -->
    <URL>http://api.myproject.com/</URL>
  </HTTPTargetConnection>
</TargetEndpoint>
After you have saved your changes, deploy the API proxy:
$ sh deploy.sh

You have now added API key validation to your backend service.

The other proxies can be modified in the same way to enforce OAuth and other types of processing available in the sample API proxies. In some cases, however, API proxy behavior is dependent on specific message formats, so they might need additional configuration changes to work with your backend services.

Help or comments?

  • Something's not working: See Apigee Support
  • Something's wrong with the docs: Click Send Feedback in the lower right.
    (Incorrect? Unclear? Broken link? Typo?)