April 6, 2015 | Written by: Matt Hamann
Share this post:
APIs are rapidly becoming one of an organization’s most important assets. Enabling customers and developers to consume APIs through their own applications and services provides a compelling system for innovation and monetization.
IBM API Management delivers a powerful mechanism for controlling API access, managing multiple versions of an API, establishing rate limits, and ultimately tracking the performance metrics and analytics of each API in your portfolio. Combined with Bluemix— IBM’s signature platform-as-a-service —we enable one-stop shopping and management of APIs from anywhere.
At InterConnect 2015, IBM launched the API Management service on Bluemix as a beta. Since then, we have been working diligently to improve the performance and stability of the service, and we are excited to announce the general availability of the API Management service on Bluemix.
Ready to try API Management?
If you’re new to our API Management tools, this video walks through the steps of this article:
Or if you want to try it yourself, this article will help you get quickly up to speed. Below are the steps you’ll follow:
- Provisioning the API Management service on Bluemix
- Creating and importing a new API
- Publishing your APIs to the Bluemix catalog and sharing them with other Bluemix organizations
- Consuming APIs from a Bluemix application.
You’ll need a Bluemix account for this tutorial. If you don’t have one already, sign up here!
Step 1: Provision the API Management service
- Open the Bluemix console and log in.
- Navigate to the catalog.
- Select the Integration filter from the left-hand menu to reduce the number of displayed options, then locate and click the API Management tile.
The service information page will appear.
- API Management presently offers a single “Standard” plan. This plan includes 5,000 free API calls per month, 1 free non-Bluemix developer portal account (developer portals are always included with Bluemix users), and 50MB of free storage space if you want to collect debug information and API analytics.
Click the Create button to provision and launch the API Management service.
- The Getting started page will appear. If you’re new to API Management, we suggest following the steps listed. If you know your way around already, feel free to go directly to API Manager. You can check out the docs at any time by clicking Learn more.
Step 2: Create your first API
The API Manager allows users to create APIs from scratch or import an existing API based on a Swagger or WSDL definition. For the purposes of this tutorial, we’ll be importing the Pet Store sample API via swagger.io.
- Click the Import APIs, or compose a new one link from the Getting started page in Bluemix. The API Manager will open in a new tab and may take a moment to load.
- Click the blue +API button, then select Import Swagger.
- Next, we can upload a Swagger document or reference one via a URL. For tutorial purposes, we’ll simply provide the URL to import. Paste the following URL into the Swagger URL field:
https://raw.githubusercontent.com/mhamann/apim-sample/master/petstore.json. Leave the Username and Password fields blank, then click Load.
- API Manager will list all of the APIs and resources contained in the Swagger document. Click Add to create the API.
- The new API is now displayed in the API list. Click the API title to open the API editor.
The API editor allows the modification of various API attributes. We can change the name, description, path, add and remove resources, and adjust options like authentication and authorization.
- Click the API path to edit it. Change it from
- Next, click the Security tab. Under the option “Identify Application Using,” select Client ID and Client Secret. Setting this option provides enhanced security for your API.
Then, click Save API near the upper-right of the page.
The API has been created successfully.
Step 3: Create a plan
Every API must be part of a plan before it can be published and invoked. API Management uses plans to manage access to API resources, set rate limits, and stage APIs into various environments (e.g. a sandbox, test, production, etc). One plan may contain resources from any number of APIs, thereby enabling access to groupings of resources at varying rate limits. Later on, we’ll publish these plans for usage in Bluemix.
In this step, we’ll create a new plan, add our API resources to it, set rate limits, and deploy it.
- Open the Plans page by clicking the plans icon in the API Manager or by returning to the getting started page and selecting the next step.
- Click the + Plan button.
- Enter a name for the plan and click Add.
- The new plan will appear in the list. Click the plan’s title to open the plan editor.
- First, add the resources from the Pet Store API to the plan. Click the + Resource button.
- The list of APIs will appear on the left and the API’s resources on the right. If not already selected, pick the Swagger Petstore API, then select all of the resources that are part of the API. Then, click Add.
The selected resources will appear in the lower portion of the plan editor.
- Next, set a rate limit for the plan. Rate limits may be set either individually for each resource -or- for the entire plan. If a rate limit is applied at the plan-level, it is applied to all of the resources in that plan.
Set the rate limit for the plan by clicking the edit icon under the Rate limit section. Set the rate limit to: 10,000 requests per 1 Days. Then, click Apply.
- Click Save in the upper-right corner of the page to persist the changes to the plan.
- Finally, deploy the plan.
Click the Deploy icon to display the deployment menu. Wait until the Sandbox option appears, then select it.
After a few moments, a success notification should appear.
At this point, the plan has been deployed and is ready to be shared with others.
Step 4: Invite others to use your APIs (optional)
One of the core tenets of API Management is the ability to allow others to use your APIs. Pairing API Management with Bluemix enables APIs to be shared from one Bluemix organization to another. If you want to share an API with another organization, follow these steps, otherwise feel free to skip to step 5.
- Open the Developers page by clicking the developers icon in API Manager, or by returning to the getting started page and selecting the next step.
- Click the + Bluemix Organization button to invite a Bluemix user to associate their organization with yours. This simply enables you to share APIs with this organization in the future.
- Enter the email address of the person with which you want to share APIs, then click Invite.
If this person is an existing Bluemix user, they must have the role of Manager or Billing Manager in their organization. If the person does not have a Bluemix account yet, they will be prompted to create one before proceeding.
- The invited user’s organization will not immediately display in the list of developer organizations. The user must check their email and accept the invitation before the new organization will appear.
Once the invitation process has been completed, proceed to step 5.
Step 5: Publish APIs to Bluemix
- Open the Management page by clicking the management icon in API Manager, or by returning to the getting started page and selecting the final step.
The list of deployed plans will be displayed.
- Click the Pet Store – Gold plan to expand the plan and display the list of currently deployed versions.
- Click the icon to launch the plan publishing wizard:
- Ensure Publish this version is selected, then click Next.
- Ensure Select group of developer organizations and communities is selected, then enter or select Bluemix in the field below. If you invited another Bluemix organization back in step #4, you can also enter their organization name here to make the API available to them as well. (Note: if the entry field isn’t showing up right away, try clicking the blue circle next to the option “Select group of developer organizations and communities” even if it’s already selected.)
- Click Publish.
A notification should appear after a few moments indicating that the publish was successful.
Step 6: Bind the API to an app
We’ve successfully created our API in API Manager and published it to Bluemix. It will now show up in our organization’s Bluemix catalog. The final step in the process is to provision the API, bind it to an app, and watch the data flow!
For the purposes of this tutorial, we’ll create a new Node.js app and then provision and bind our API to it. (Any application type— not just Node.js —may be used to consume this API.)
- Open the Bluemix dashboard and click Create an app.
- Click Web.
- Click SDK for Node.js, then click the Continue button.
Give the app a name, then click Finish. (This name should be unique, so be creative or just use your initials.)
- Once the app has been created, click the Overview section.
- Next, click Add a service or API. The Bluemix catalog will appear. Select the filter for Custom APIs on the left-hand sidebar, then click the Swagger Petstore tile to open the API details.
Details about the API will be displayed, including all of the resources it provides, parameters, sample responses, and so on.<
- Notice, the app we created is already selected, so simply press the Create button to provision the API and bind it to the application. If you are asked to restage the application, click Restage. The Swagger Petstore is now bound to the application. We need only to test it and ensure that it works.
- Finally, let’s obtain the APIs credentials and test it out. On the left, click Environment Variables.
The variables for
VCAP_SERVICES should be displayed, which include the details for our Swagger Petstore API. Primarily of interest are the credentials, which contain the Client ID, Client Secret, and URL we need in order to invoke the API.
Step 7: Test the API
A tool like Postman may be used to test the API. We’ll demonstrate this here.
- Open the Postman utility or an equivalent.
- In the URL field, enter the URL like this:
<credentials.url>/pet/findByTags?tags=tag1&client_id=<credentials.client_id>&client_secret=<credentials.client_secret>(Substitute the portions wrapped by < > with the appropriate value from your environment variable’s credentials.)
In Postman, the setup looks like this:
- Click Send to execute the API request. If everything proceeds normally, the output should look something like this:
Congratulations! You’ve just set up a managed API, published it through a plan, and invoked it!
– Matt Hamann (@mhamann) – Software Engineer, Bluemix Cloud Integration
– Belinda Vennam (@BeeMarieV) – Software Development Manager, Bluemix Cloud Integration