This tutorial demonstrates how to expose and manage a Heroku backend using the WSO2 API Cloud add-on.
Before you begin,
In this tutorial you will:
Deploy a sample application on Heroku
You need to create a sample application on Heroku to understand how you can use WSO2 API Cloud to expose an application as an API.
In this tutorial we will use a simple Node.js REST service application to create and deploy a sample application on Heroku. The sample application implements a simple echo service that takes a text parameter and returns the word Hello along with the specified parameter.
Follow the steps below to deploy a sample
node.js application on Heroku:
Execute the following command to clone the sample node.js REST service application:
- Navigate to the directory where the sample application got cloned.
Execute the following command to create a new Heroku application:
Execute the following command to deploy the sample code to the new Heroku application:
Execute the following command to Ensure that you have at least one instance of the service running:
- To verify that your web service is running, append
/hello?name=Worldto the root URL of your Heroku application and navigate to it via your browser. For example, if
https://boiling-scrubland-10078.herokuapp.com/is the root URL of your Heroku application, append
/hello?name=Worldto the URL (i.e.,
Associate your Heroku application with WSO2 API Cloud
Follow the steps below to provision the WSO2 API Cloud add-on to your Heroku application.
- Sign in to Heroku and go to the Resources page of the new Heroku application you created.
- Under the Add-ons section, search for WSO2 API Cloud and select it to provision the add-on.
- Select the appropriate Plan name and click Provision. This lists WSO2 API Cloud under the Add-ons section.
- Click the WSO2 API Cloud add-on. You will be asked to provide your WSO2 API Cloud password.
- Enter your WSO2 API Cloud password and click Submit. This takes you to a page where you need to select your WSO2 Cloud organization.
- Select the WSO2 Cloud organization that you want to associate with your Heroku account and click Go. This takes you to your WSO2 API Cloud dashboard.
Now that you have associated your Heroku application with the WSO2 API Cloud add-on, see the next section for information on how to expose an API for your Heroku backend.
Define a managed API for your Heroku backend
Follow the steps below to expose an API for your Heroku backend.
On your WSO2 API Cloud dashboard, click ADD NEW API.
Select Design a New REST API and then click Start Creating.
Enter the following general details to design your API appropriately:
- Visibility on Store:
In the API Definition section, enter
helloas the URL Pattern, select GET, and then click Add.
- Expand the new
/hello GETmethod and add a new parameter as follows:
- Click Implement.
- Expand the Managed API section and provide your Heroku app’s root URL as the Production endpoint.
- Click Manage.
- Under the Throttling Settings section, select Unlimited as your API’s Subscription Tier.
- Set the API security to None:
- Click Save & Publish. This displays a message confirming that you have succesfully published your API.
- Click Go to API Store to open your API in the API store. API store is the developer portal of WSO2 API Cloud.
- In the API Store, click the API Console tab.
- Expand the
/hellomethod of your API, provide a value for name (for example, World), and click Try it out!.
You will see that the API calls your backend service in Heroku and displays the execution results.
Now that you have successfully created an API for your Heroku application, you can try out the other API management capabilities that the WSO2 API Cloud add-on supports.