Try WSO2 Cloud for Free
Sign in

All docs This doc
||
Skip to end of metadata
Go to start of metadata

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:

  1. Execute the following command to clone the sample node.js REST service application:

    git clone https://github.com/wso2/cloud-heroku-samples.git
  2. Navigate to the directory where the sample application got cloned.
  3. Execute the following command to create a new Heroku application:

    heroku create
  4. Execute the following command to deploy the sample code to the new Heroku application:

    git push heroku master
  5. Execute the following command to Ensure that you have at least one instance of the service running:

    heroku ps:scale web=1
  6. To verify that your web service is running, append /hello?name=World to 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=World to the URL (i.e., https://boiling-scrubland-10078.herokuapp.com/hello?name=World).

Associate your Heroku application with WSO2 API Cloud

Follow the steps below to provision the WSO2 API Cloud add-on to your Heroku application.

  1. Sign in to Heroku and go to the Resources page of the new Heroku application you created.
  2. Under the Add-ons section, search for WSO2 API Cloud and select it to provision the add-on.
  3. Select the appropriate Plan name and click Provision. This lists WSO2 API Cloud under the Add-ons section.
  4. Click the WSO2 API Cloud add-on. You will be asked to provide your WSO2 API Cloud password.
  5. Enter your WSO2 API Cloud password and click Submit. This takes you to a page where you need to select your WSO2 Cloud organization.
  6. 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.

  1. On your WSO2 API Cloud dashboard, click ADD NEW API.

  2. Select Design a New REST API and then click Start Creating.

  3. Enter the following general details to design your API appropriately:

    • NameHeroku
    • Contextheroku
    • Version1.0
    • Visibility on StorePublic
  4. In the API Definition section, enter hello as the URL Pattern, select GET, and then click Add.

  5. Expand the new /hello GET method and add a new parameter as follows:
  6. Click Implement.
  7. Expand the Managed API section and provide your Heroku app’s root URL as the Production endpoint.
  8. Click Manage.
  9. Under the Throttling Settings section, select Unlimited as your API’s Subscription Tier.
  10. Set the API security to None:
  11. Click Save & Publish. This displays a message confirming that you have succesfully published your API.

  12. Click Go to API Store to open your API in the API store. API store is the developer portal of WSO2 API Cloud.
  13. In the API Store, click the API Console tab.
  14. Expand the /hello method 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.


  • No labels