Practical Guide: How to Use WSO2 APIM 4.0 for Integration

Rosen Silva
5 min readMay 7, 2021

WSO2 announced its latest APIM + Integration platform in May 2021. You can find more details about the new Product Release of WSO2 APIM 4.0 here.

This article will explain how to use WSO2 Integration Runtime to do your complex integration tasks(message routing, transformation, message mediation, service orchestration, database services, connecting 3rd party applications through connectors, etc) and expose these Integration Services as Managed APIs.

Let’s start with a Hello World sample

Assume we have the following API definition(Swagger file or OAS definition)for our Hello World app that returns {“Hello”: “World”} as the response.

openapi: 3.0.1info:title: HelloWorlddescription: API Definition of HelloWorldversion: 1.0.0servers:- url: http://localhost:8290/HelloWorldpaths:/:get:responses:default:description: Default response

To Try Out this quick example you need to install,

Let’s first start the Integration Studio and click on New Integration Project and give a name to the Integration Project.

Create a New Integration Project

Then, right-click on the Integration Config project and select New->Rest API.

Create a new REST API in the integration project

Now we need to select Generate API using the Swagger Definition option and provide the Hello World OAS definition file that we had at the beginning of the sample

Provide the Swagger File and create the Skeleton for the API

Once you create the Synapse API using the API definition file, you will see the API representation in the graphical editor

Graphical representation of API of the Integration Service

Here you can drag and drop any mediator or connector(https://apim.docs.wso2.com/en/latest/integrate/integration-use-case/connectors/) from the palette to implement your integration logic. For our hello world sample let’s only change the response to {“Response”: “Hello World”} by clicking on the PayloadFactory mediator.

Changing the response of the Hello World Service API implementation

Now we have completed the implementation of the Integration for the API. Let’s now create a managed API for this Integration Service using the Service Catalog.

We need to change the auto-generated serviceUrl in the metadata file from “https://{MI_HOST}:{MI_PORT}/HelloWorld" to “http://localhost:8290/HelloWorld". Also, make sure to make this service URL as HTTP since we are not securing the endpoint in this sample.

Changing the service URL from the metadata file for HelloWorld API

Let’s start the WSO2 API Manager by executing api-manager.sh or api-manager.bat according to your operating system.

After the API Manager server is up and running, let’s configure the Integration Studio to connect with the API manager. For this, you need to configure the built-in Micro Integrator runtime using the Server Configuration tool. Click on the Server Configuration icon in the toolbar, and uncomment all the configurations under [[service_catalog]] and click Save

Configuring the Micro Integrator runtime to connect with the APIM service catalog

Now let's deploy the Hello World API integration app to the micro-integrator within the IDE. You need to right-click on the CompositeApplication Project and select Export Project Artifacts and Run option and select all the projects the next dialog box

Run the created Integration App using the built-in micro integrator

Wait till the micro-integrator starts completely. Then you should see the server logs saying that the API is successfully uploaded to API Manager via the Service catalog

Console log saying the API is now registered via a service catalog

Let’s move to the API Manager web portal to create a managed API for our integration use-case. For this, you need to open your web browser and enter https://localhost:9443/publisher/service-catalog

API Manager Service Catalog portal

Here you should see HelloWorldAPI is created via Integration Studio. Now to create the API in the API Manager you need to click on the HelloWorldAPI and click on the Create API button

Create API using Service Catalog

After creating API you should see something similar to the following screenshot

Created API in the API Manager

Now click on the Deploy link to deploy the API as Managed API. Keep the default Gateway and Click the Deploy button

If you successfully deployed the API you should see something as follows

Now go back API Manager home page and select the HelloWorldAPI and click the Deploy button to publish the Hello World API in the API Manager

Click Publish button to publish the API

Now we are done with Publishing the HelloWorldAPI that we have created via Integration Studio.

Let’s try out our Hello World API using Developer Portal. Open the browser and navigate to https://localhost:9443/devportal/apis

We need to Subscribe to the app to try this API. Go to Subscription from the left-side menu and click Subscribe button using the default application

Subscribe to the default application

After Subscribing, Click on the Try Out from the left-side menu. In this Try-Out section, you need to generate Test Keys by clicking the Get Test Keys button. After generating the test keys you should see something similar to the following

Test keys generated for trying out the API

Now expand the GET method named as /hello and click on the Try it out button. Finally, click Execute to see the response

Click on the Execute Button

You should now see the {“Response”: “Hello World”} response from the Integration Service API.

Response from Integration Service via Managed API

With that, we have completed the Hello World Sample for Integration using WSO2 API Manager 4.0.

You can learn more about this platform from the official documentation: https://apim.docs.wso2.com/en/latest/

Thanks for reading :)

--

--

Rosen Silva
Rosen Silva

Written by Rosen Silva

Associate Technical Lead @WSO2

No responses yet