You can use WSO2 Integration Cloud to host the backend applications for the APIs that you create in WSO2 API Cloud. WSO2 API Cloud is a platform that enables you to expose business capabilities as APIs and manage their lifecycles, from creation to publication and retirement.
Let's get started!
Creating the database
Let's create a MySQL database in the Integration Cloud to insert our buzzwords.
Log in to WSO2 Integration Cloud by going to https://wso2.com/cloud/, clicking the Sign In link and then selecting WSO2 Integration Cloud.
The Integration Cloud opens. Click CREATE DATABASE.
Enter the following information in the form that opens, scroll down and click Create Database.
- Database Name: TestDB
- Default User Name: user1
- Give a suitable password
The database that you just created appears in the console. Copy the database name, URL and username.
Tip: You see additional characters in the database name and user name because the Cloud adds them to uniquely identify the tenant of the database and the user.
In the command-line or the terminal, run the following command to log in to the MySQL database that you just created. Note that some MySQL clients provide GUIs to connect to the databases.
Run the following command to create a table by the name
Buzzwordsin the database.
Run the following command to insert some test data to the table:
You now have a database created.
Creating the backend application
Let's create an application in the Integration Cloud that connects to the database that you created earlier.
- Sign in to WSO2 Cloud and go to the Integration Cloud tab. Then, click Java Microservices.
Select the Local File System option and click Continue.
Enter the following details in the form, scroll down and click Create.
- Application Name: API Producer
- JAR file: Download this sample Java Microservices application and upload it.
Under Advanced Settings...
Field Value Runtime
OracleJDK 8 + WSO2 MSF4J 1.0.0 - Deprecated
This sample was written for WSO2 MSF4J version 1.0.0.
Tip: Be sure to always select the same deployment environment that you used to develop the sample. If not, the sample might not work properly.
Scroll down to the Environment Variables section and add the following to read and write data from/to the database that you created earlier:
Type " database: " -> select the database -> select URL and click Add.
Type " database: " -> select the database -> select Users -> Select the username and click Add.
<Give your database password>
Once the application is created, the application's homepage opens. Copy the application's URL.
You have now created an application that connects to the database in the Integration Cloud.
Creating an API to consume the backend application
Let's create an API in WSO2 API Cloud with the backend application as its endpoint. This way, users who subscribe to your API after it is published can insert or retrieve buzzwords without writing the application code themselves.
- Log in to WSO2 API Cloud by going to https://wso2.com/cloud/, clicking the Sign In link and then selecting WSO2 API Cloud.
- Click ADD NEW API.
- Select the Design new REST API option and then click Start Creating.
Add the following information under the Design tab, scroll down and click Next: Implement to go to the next tab:
Field Value Name buzzwordapi Context /buzzwordservice Version 1.0.0 API Definition
Add two API definitions as follows:
- URL pattern: all and HTTP method: GET
- URL pattern: mostPopular and HTTP method: GET
- URL pattern: all and HTTP method: GET
The Implement tab opens. Click the Managed API section to expand it, enter the following information, scroll down, and click Next: Manage to go to the next tab.
Field Value Endpoint Type HTTP/REST Endpoint Production Endpoint
You got the
< DEPLOYMENT_URL >in step 4 of the previous section. In this example, the production endpoint is https://companyn-api-producer-1-0-0.wso2apps.com/buzzword.
The Manage tab opens. Enter the following information, scroll down, and click Save and Publish.
Field Value Make this the Default Version Check Transports HTTP/HTTPS Subscription Tiers Gold
- Choose to go the API Store when prompted.
- The API opens in the API Store.
Next, let's invoke the API that you just created.
Invoking the API
WSO2 API Store has an integrated Swagger console called the API Console, which allows you to invoke the APIs that are published in the API Store through a simplified graphical interface. Swagger also facilitates simple, interactive API documentation.
Before you invoke an API, you must subscribe to it using an application and a throttling tier. An application is a logical collection of APIs. It is primarily used to decouple the consumer from the APIs by allowing you to generate a single key for multiple APIs and subscribe to a single API multiple times with different SLA levels.
A throttling tier allows you to limit the number of successful hits to an API during a given period of time, typically to protect your APIs from security attacks, to regulate traffic according to infrastructure availability, and for monetization.
- In the previous step, you opened the newly created API in the API Store. From the API's subscription options that open on the right-hand side of the screen, select
Goldtier, and click Subscribe.
- Click View Subscriptions when prompted.
Go to the Production Keys tab and click Generate Keys to create an access token.
You need an access token to be authenticated to invoke the API. An access token is a simple string that is passed as an HTTP header of a request to authenticate API users and applications. Access tokens expire after 1 hour by default. You can either extend the expiration period before it expires or click Regenerate to renew an access token.
Next, let's invoke the API.
- Click the APIs link in the API Store and then click the API you want to invoke.
- Go to the API Console tab of the API, expand one of the methods (e.g., /all), and click Try it out.
- Note the results that appear in the API Console.
You have now invoked the backend application in the Integration Cloud using the API that you created in the API Cloud.