Was this helpful?

Apigee API Platform samples are designed to help developers learn how to use the Apigee API Platform. The package contains sample API proxies, policies, code, and tools that illustrate the capabilities of the Apigee API Platform.

Where to get samples

If you have git installed, run:

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

If you do not have git installed, you can browse and download the samples from the API Platform Samples Github Repo.

How to use samples

All of these samples require you to have an account on https://enterprise.apigee.com.

You can sign up for a trial account at https://enterprise.apigee.com/signup.

To use the included deployment tool, you also require Python to be installed on your machine.

After yo download the samples

$ cd /setup

In the /setup directory, locate the file setenv.sh

In this file, provide settings for your organization, username, and the environment where you want to deploy the API proxies.

After you setup setenv.sh, run:

$ sh deploy_all.sh

This script deploys all API proxies samples to your organization. (The process takes 3-4 minutes.)

Follow prompts to deploy API products, developers, and apps (which are used for OAuth

).

Once 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 are two scripts:

  • 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

These scripts are designed to help you iterate quickly, as you make small changes, deploy and invoke to see what effect you change had. This type of iterative development is a great way to investigate the behavior of policies and scripts.

Sample API proxies

The following API proxies are available in this distribution:

Name Description Policy Types Resources
apikey Implements simple API key validation VerifyAPIKey Quota None
conditional-policy Implements simple conditional policy enforcement. When a request contains an HTTP header responsetime:true, a policy executes a Python script that adds a set of performance metrics to the response message, as HTTP headers Python timer.py
conditional-routing Implements simple conditional routing. When a request contains an HTTP header routeTo, the ProxyEndpoint dynamically routes to the specified URL. None None
dynamic-endpoint Implements simple conditional routing in a lsightly more complex scenario, that defines two URLs and one default route. None None
javascript-mashup A complete JavaScript application that calls to public APIs, combines results, and generates an enriched response for the client app. (Note: this API proxy implements the same functionality as the policy-mashup, demonstrating that the same problem can be addressed using different techniques.) Javascript, StatisticsCollector MashItUp.js
oauth-authcode Demonstrates a fully functional OAuth 2.0 token and authorization endpoint configuration. GenerateAccessToken, GenerateAuthCode, RefreshAccessToken None
oauth-client-credentials Demonstrates a fully functional OAuth 2.0 token endpoint configured for the client credentials grant type. GenerateAccessToken None
oauth-login-app Demonstrates a fully functional OAuth 2.0 token and authorization point configured with a sample login app. GetOAuthV1Info, AssignMessage, GenerateAcceesToken, GenerateAuthorizationCode, RaiseFault None
oauth-verify-accesstoken Demonstrates a n API configured to validate OAuth 2.0 access tokens and verify Quota. VerifyAccessToken, Quota None
policy-mashup A complete application that uses policy composition to call two public APIs, combines results, and generates an enriched response for the client app. (Note: this API proxy implements the same functionality as the javascript-mashup, demonstrating that the same problem can be addressed using different techniques.) AssignMessage, ServiceCallout, ExtractVariables, JavaScript, RaiseFault, StatisticsCollector GenerateResponse.js
simple-javascript Demonstrates a simple JavaScript snippet that transforms an XML-formatted weather report from JSON to XML, and trims content down for mobile clients. JavaScript transform.js
simple-python Demonstrates a simple JavaScript snippet that sets HTTP response headers using a predefined variable. Script setHeader.py
soap Demonstrates an XSL transformation that rewrites a WSDL file in response to a request with the query parameter ?wsdl. AssignMessage, ExtractVariables, Script, XSL calculateaddress.py, fixwsdl.xsl
twitter-mobile-timeline Demonstrates how to use JavaScript to strip out unneeded parameters from tweets, resulting in a streamlined Twitter timeline that is friendly for resource-constrained mobile devices. JavaScript CORS.js, MobileTimeline.js
twitter-oembed Transforms timeline responses (e.g. from statuses/user_timeline.json) into an oEmbed response that contains the timeline data as rich HTML content. JavaScript cors.js, timeline-oembed.js
twitter-translate The most sophisticated sample, this API proxy uses the Microsoft Azura translator API to translate tweets. To do so, it makes an outbound call to obtain an OAuth access token, and then caches the token using the API Platform caching policies, reusing the cached token each time an outbound call is made. Also, includes a demonstration browser app used to invoke the API proxy. AssignMessage, LookupCache, PopulateCache, JavaScript api-config.js, api-token-get.js, cors.js, timeline-translate.js, translate-query.js, translate-results.js
xmltojson Converts a Yahoo API weather report from XML to JSON. XMLtoJSON None

Reference and Tools

/simpleProxy

A basic API proxy that is used in the API Platform Developer Guide. The Developer Guide shows you how to build API proxies that run on the API platform, with instructions on API Keys, OAuth 1 and 2, developer and app provisioning, custom scripting tutorials, environment configuration, and more.

/schemas

XML schema files that you can use as a reference when configuring API proxies, policies, API products, and developer and app profiles.

/tools

Contains a deployment tool, deploy.py, that imports an API proxy to an organization on the API Platform and then deploys it to the environment specified.

 

Get support

Share your experiences on the Apigee Developer Forum.