Tuesday, July 14, 2015

WSO2 ESB - Connecting APIs with Call Mediator


In this post i'm going to discuss an API interconnecting scenario with aid of an simple use case. Here the use case is as follows. We have two apis 1. Which gives the city name when longitude, latitude coordinates are given. 2. An API which gives temperature of a city (when city name is given). Here my objective is to combine (chain) both apis and get the temperature when lon-lat is given.

First we will create the mock APIs for  Map API and Weather API. To create APIs I used WSO2 Developer Studio [1]. Using DevStudio I created a JAX-RS project and deploy it on WSO2 AS[2]
Source code for Map service and Weather service is as follows.


You can download the war file from here. Once deployed the war file on WSO2 AS, you would be able to access the API's as follows. Note that i have set portOffset of WSO2 AS as 2 since i run both servers in same machine.

http://localhost:9765/SimpleMap_1.0.0/services/weather/gettemperature?city=Kandy

First one will give {"city":"kandy"} as the output and second will give the 24.5 as the temperature output.

Now it is the time to play with WSO2 ESB to chain the above two apis. Please have a look at ESB config below, As code says what it does i'm not going to explain in detail. Figure below show the DevStudio view of the API.



Now you can call the ESB api directly to get the temperate when the coordinates of the location is given.
http://localhost:8280/MapService/gettemperature?x=7&y=80

References
[1] - http://wso2.com/products/developer-studio/
[2] - http://wso2.com/products/application-server/
[3] - http://wso2.com/products/enterprise-service-bus/

1 comment:

orubel said...

The term 'api chaining' was originally created and copyrighted by Owen Rubel. Please cease and desist usage without proper implementation and acceptable acknowledgement of copyright ownership.