Practical Guide: How to Use WSO2 APIM 4.0 for Integration
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,
- Integration Studio — https://wso2.com/integration/integration-studio/
- WSO2 API Manager 4.0.0 — https://wso2.com/api-manager/
Let’s first start the Integration Studio and click on New Integration Project and give a name to the Integration Project.
Then, right-click on the Integration Config project and select New->Rest API.
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
Once you create the Synapse API using the API definition file, you will see the API representation in the graphical editor
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.
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.
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
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
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
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
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
After creating API you should see something similar to the following screenshot
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
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
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
Now expand the GET method named as /hello and click on the Try it out button. Finally, click Execute to see the response
You should now see the {“Response”: “Hello World”} response from the Integration Service 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 :)