Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This sample demonstrates how to subscribe to a published API and consume its functionality using the API Store Web application. We use the Wikipedia API here.

Building the Sample

Execute the steps in Samples Setup. When you are done, you will have the API Manager started and the relevant scripts run to create user accounts for API Publisher and API Store.

 

Note

The scripts used for this sample do not work in Windows. Support for Windows will be added in an upcoming release.

Executing the Sample

  1. If you haven't done so already, start the API Manager and log in to the API Publisher(http://localhost:9763/publisher) using credentials provider1/provider1.
  2. There are no APIs created yet. To create one and publish it to the API Store, run the following:
    • On Linux: <APIM_HOME>/samples/WikipediaAPI/APIPopulator.sh
    • On Windows: <APIM_HOME>/samples/WikipediaAPI/APIPopulator.bat
  3. Refresh the API Publisher to see the Wikipedia API created.
  4. You can now access Wikipedia through this newly-deployed API. Log in to the API Store (http://localhost:9763/store) using credentials subscriber1/subscriber1.
  5. Select the Applications tab at the top of the page, and create a new application. Provide any name you like.
  6. Select the APIs tab at the top of the page, select the WikipediaAPI API and subscribe to it using the newly-created application.
  7. Go to the My Subscriptions tab and select your application. Click the Generate button associated with the production system to obtain an application access token.
  8. You are now ready to invoke the API. Copy and paste following into a new console and execute it. Be sure to replace the string '9nEQnijLZ0Gi0gZ6a3pZICktVUca' with the application access token you obtained earlier.

    Code Block
    curl -H "Authorization :Bearer 9nEQnijLZ0Gi0gZ6a3pZICktVUca" "http://

...

  1. localhost:8280/wikipedia/1.0.0?format=json&action=query&titles=MainPage&prop=revisions&rvprop=content"
  2. You must see the JSON result from the Wikipedia API on you console. For example,

    Code Block
    {"query":{"pages":{"5982813":{"pageid":5982813,"ns":0,"title":"MainPage","revisions":[{"contentformat":"text/x-wiki","contentmodel":"wikitext", "*":"#Redirect [[Main Page]]\n\n{{Redr|mod|rcc}}"}]}}}}... 

    See http://www.mediawiki.org/wiki/API:Main_page for more information about the Wikipedia API. You can try out various API actions and features similar to step 9.