In this tutorial, you will package and deploy API definitions to IBM Blumix so they are accessible outside of your local environment. In a real-world scenario, you would publish them into a dev portal where developers subscribe to the API and obtain an API key. For testing purposes, you will simply use a development API key.
Authors
Prerequisites:
-
API Connect Developer Toolkit 5.0.7.1
-
Import the API definitions file from
- https://github.com/ozairs/apiconnect/blob/master/bluemix/weather-provider-api_1.0.0.yaml
- https://github.com/ozairs/apiconnect/blob/master/bluemix/weather_1.0.0.yaml.
- https://github.com/ozairs/apiconnect/blob/master/bluemix/oauth_1.0.0.yaml.
- https://github.com/ozairs/apiconnect/blob/master/bluemix/utility_1.0.0.yaml.
See instructions here
-
For testing, you will to download Postman.
-
Download the Postman collection here
Instructions:
Note: New terminology will be discussed in subsequent sections, so let's formerly define them now:
- Product: packaging of one or more APIs into a single group that is a deployable unit and enables enforcement of rate limit definitions.
- Catalog: deployment target for a
product
and provides access to many API management capabilities.
- Login to Bluemix and select the Catalog link. In the search box, type API Connect and click on the API Connect link.
- Select the Essentials plan and click Create and follow the prompts to provision the service. The provisioning steps may take a few moments to complete.
- Once complete, you should be redirected to the Dashboard and see a large icon with the name
Sandbox
. - Click the Sandbox catalog to open the Dashboard and then click on Settings.
- In Overview, the Automatic subscription toggle should already be selected. Click the Show button to note the client ID and client secret. For example, client id is
d03c438a-2010-4f21-8520-c111a86a9f16
and client secret isrH1lA6wO5nL6gC5uD5tV0pE1hV4gO5lV2yN2uG5hB1hR3iT6jF
. - Select Endpoints and make a note of the URL, such as
https://api.us.apiconnect.ibmcloud.com/ozairscaibmcom-dev/sb/
.
Let's switch back to the API Connect Developer toolkit.
- Click the APIs tab and select the Weather Provider API.
- Select the Design tab.
- Modify the API definitions that are using
127.0.0.1:443
.- Click the Source tab in the Weather API and find and replace
127.0.0.1
withapi.us.apiconnect.ibmcloud.com/ozairscaibmcom-dev/sb/
- Repeat the same steps for the **
127.0.0.1
withapi.us.apiconnect.ibmcloud.com/ozairscaibmcom-dev/sb/
. Remove any extra slashes if needed.
- Click the Source tab in the Weather API and find and replace
- Click the Save icon. Your all set to publish the product to IBM Bluemix!
- Click the Publish button in the nav bar.
- Click Add IBM Bluemix target, and sign-in with your credentials.
- The Sandbox catalog provisioned will be shown. Make sure its selected and click Save.
- Click the Publish button (leave the defaults unchecked) and make sure you get a successful publish message. Now we have to go back to the Sandbox catalog in IBM Bluemix to obtain the URL for testing.
- Open Postman and right-click the OAuth Password request and clone the request (right-click and select Duplicate). Change the URL to reflect your endpoint but keeping
/oauth/token
. For example changehttps://127.0.0.1/oauth/token
tohttps://api.us.apiconnect.ibmcloud.com/ozairscaibmcom-dev/sb/oauth/token
. - In the Body tab, change the client id and client secret to reflect your values obtained in the previous steps. Click Send and make sure you get back an access token.
- Repeat the steps above to change the Weather request to invoke it with the access token from the previous step. Make sure you get back a valid response!
In this tutorial, you learned how to publish your API definition to Bluemix for availability outside your local environment.