[Architecture Blog] Implementing an API Façade with the WSO2 API Management Platform

  • By Asanka Abeysinghe
  • 14 Oct, 2015

Business scenario: A backend service with SOAP binding required to expose as a RESTful service and secured using OAuth. Consumers require responses in either XML or JSON using the same API.

Technical requirements: SOAP to REST protocol switching, content negotiation, XML to JSON conversion.


Reference architecture

Based on the recommended API Façade Pattern in my previous blog, the architecture looks like following diagram:

Figure 1

The API Gateway (one of the roles in the WSO2 API Management Platform) will expose the RESTful API. The Mediation layer will do the protocol bridging and connect to a backend service with the SOAP binding.

Lets look at the implementation with WSO2 middleware products:

Figure 2

WSO2 API Manager and WSO2 Enterprise Service Bus (WSO2 ESB) will be the primary middleware components used to build this façade pattern.

Mediation logic (using standard EIP notations) looks like below.

Figure 3


API definition in WSO2 API Manager (gateway)


Mediation in WSO2 ESB


Commands to invoke the API

XML response :
curl -v -H "Authorization: Bearer zBAIbMiXR4AJjvWuyrCgGYgK2Osa" -X GET

https://localhost:8280/ordersoap/1.0.0/view/JBLU


JSON response:
curl -v -H "Authorization: Bearer zBAIbMiXR4AJjvWuyrCgGYgK2Osa" -X GET

https://localhost:8280/ordersoap/1.0.0/view/JBLU -H "Accept: application/json"

To view the JSON message properly in CMD

curl -v -H "Authorization: Bearer zBAIbMiXR4AJjvWuyrCgGYgK2Osa" -X GET
https://localhost:8280/ordersoap/1.0.0/view/JBLU -H "Accept: application/json" | python -mjson.tool

In the above sample WSO2 API Manager running with default offset (0) and WSO2 ESB running with offset 3.

Note: If you want to use the anti-pattern of doing both Facade and mediation in the same layer, you can copy the ESB configuration to API Gateway configuration and get the same functional result.