paint-brush
Designing and Developing the Integration of Your Online Shopping Storeby@rusirij
346 reads
346 reads

Designing and Developing the Integration of Your Online Shopping Store

by Rusiri IllesingheAugust 16th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Let’s see how to design and develop the integration of an Online Shopping Store using WSO2 Integration studio!

People Mentioned

Mention Thumbnail

Company Mentioned

Mention Thumbnail
featured image - Designing and Developing the Integration of Your Online Shopping Store
Rusiri Illesinghe HackerNoon profile picture


“Design and develop an integration..” The words seems so heavy ? But I’m going to show you the best way to get it done easier, from my experience! There is WSO2 Integration Studio, a World Class Integration solution which is available as Open Source!


WSO2 Integration Studio is a development environment for designing, developing, debugging, and testing integration solutions. It has a graphical editor which facilitates with drag and drop design for integrations, and a source editor in addition for that. When you create REST APIs you can use the Swagger editor to make use of Swagger definitions. Also this has a Micro Integrator embedded in it, so that the developers can deploy and test the integrations as well.


Let’s see how to design and develop the integration of an Online Shopping Store using WSO2 Integration studio!


‘ShopMe’ is a large Online Food Store which sells the products from three manufacturers (‘BakeMe’ , ‘FoodX’ and ‘EatMore’) and allow the customers to compare the products regarding the product prices, reviews and buy the best product that suits for them.

System in High Level— Image by Rusiri Illesinghe


The manufacturers ‘BakeMe’ , ‘FoodX’ and ‘EatMore’ are exposing their own APIs to access the product related information. But the user has to put an extra effort to visit each website, compare the product prices, see the reviews and select the best product for them. So, the ‘ShopMe’ online store needs to create a single API, integrating all APIs of the product manufacturers.

Step 1

Download and install the WSO2 Integration Studio. You can refer the following URLs for this process.


https://wso2.com/integration/integration-studio/

https://apim.docs.wso2.com/en/latest/integrate/develop/installing-wso2-integration-studio/


Step 2 :

Now let’s create the integration!

a) First, open the WSO2 Integration Studio and click on “New Integration Project**”** as in the image shown below.


b) Let’s create our Integration project with the name ‘ShopMe’

c) Make sure it has checked the ‘Create ESB Configs’ and ‘Create Composite Exporter’ check boxes as above. Then click ‘Finish’ button.

Now our project should be visible in the Project Explorer as follows :

Step 3:

Next we’ll create the endpoints.

Endpoints are corresponding to the services provided by ‘ShopMe’. Since ‘ShopMe’ is unifying the services provided by three food stores, we have to create three endpoint artifacts. Let’s create them!

a) Right click the ‘ShopMeConfigs’ and select New →Endpoint

b) In the following popup window, click ‘Next’.

c) We’ll create the endpoint for ‘BakeMe’.


For URI We select the endpoint as a ‘Static Endpoint’ to save it in the current workspace. You can change the URI template in accordance with the manufacturer APIs you use.

Provide the following endpoint information and click ‘Finish’.

d) Create the endpoints for ‘FoodX’ and ‘EatMore’ as well, following the above steps a, b and c repeatedly.


You can use the following endpoint information when creating the endpoints :


Endpoint Name : FoodXEndpoint

Endpoint Type : HTTP

Endpoint URI Template : http://localhost:9091/foodX/products/{uri.var.productType}

Method : GET


Endpoint Name : EatMoreEndpoint

Endpoint Type : HTTP

Endpoint URI Template : http://localhost:9092/eatMore/products/{uri.var.productType}

Method : GET

Step 4:

Now let’s create the REST API for our ‘ShopMe’ platform! Our intention is to orchestrate the above three services and expose them as a single API to the userbase.


a) Right click on ‘ShopMeConfigs’ and select New →REST API as follows :

b) Select ‘Create A New API Artifact’ in the appearing window and click ‘Next’.


c) Let’s give the API name as ‘ShopMeAPI’ and context as ‘shopme’ and click on the ‘Finish’ button.

Step 5:

Let’s design the integration!


a) Open the ‘ShopMeAPI’ in Design view as follows :

b) Let’s set the properties for ‘API Resource’. When you double click it in the design view, you may see the properties window in the screen. There you have to set the following values.


Url Style: URL_TEMPLATE

Uri Template : /products/{productType}

Methods : GET


In the right side palette you can find different types of mediators, which you can drag and drop into the design canvas.


For your knowledge about the Mediators, I’m quoting the following from WSO2 official documentation,

"Mediators are individual processing units that perform a specific function on messages that pass through the Micro Integrator.”

Our requirement is to add the endpoint artifacts of ‘BakeMe’ , ‘FoodX’ and ‘EatMore’ into this integration sequence, in our design.


c) When our ‘ShopMeAPI’ receiving a GET request, it should call the endpoints of thee above three services. That means, when the ShopMe API receives a message, it should create three clones. For this we use the ‘Clone Mediator’. Drag and drop it into the design as follows :

By default we can see that, clone mediator has one branch, since it should be three branches in our case, right click on the call mediator and select ‘Add/Remove Target..’. Set the number of branches as 3 there and click ok.

Now you may see that the design also has been updated with three branches.


c) For sending a message to an endpoint outside of the Micro integrator we can use ‘Call Mediator’.


So let’s drag and drop the call mediator into the design like this:

d) To which endpoint the message should go ? Yeah we are going to define that in our design!

Under the ‘Defined Endpoints’ on the right hand side pane of the window, you may see the three endpoints that you created previously. We’ll frag and drop the corresponding endpoint for each call mediator.

e) So far, we prepared our design as to clone the message and deliver to three different services. With that, we may receive three different responses from those three messages sent to three services. We know that the purpose of ShopMe API is to provide a single interface for all those 3 services.


For example when a user is interacting with ShopMe to get all the ‘Cake’ products, the ShopMeAPI will receive the corresponding API call (a message). Since it needs to get the cake products of ‘BakeMe’, ‘FoodX’ and ‘EatMore’, the particular message is cloned and sent to those three endpoints and those services will respond back to the ShopMeAPI individually. With that, ShopMe API will receive three responses (messages) and it should aggregate them and expose as a single response.


For this we can use the ‘Aggregate Mediator’. So let’s drag and drop it to our design, next to the call mediators.

Double click on the aggregate mediator and set the following expression for ‘Aggregation Expression’ : json-eval($.products.product)


f) Now we need to send the aggregated response back to the client. For that, we use a Respond mediator, next to the Aggregate mediator.


This is the complete design for our integration.

Cool! We could comfortably prepare our integration design with several drag and drop rounds with this smart tool!


Let’s build and run the created artifacts!

Step 6:

This step have two main alternatives!

  1. WSO2 Micro Integrator is another wonderful open source solution from WSO2, to deploy and run the integration artifacts. You can use it externally and deploy the integration. Will write on it soon!
  2. You may remember that I initially mentioned that WSO2 Integration Studio has it’s own Micro Integrator embedded. Hence you can deploy and run the integration using the Integration Studio itself!

In this article, let’s go ahead with the second option I mentioned above.


First we have to build the artifacts. For that, right click on the ‘ShopMeCompositeExporter’ and select ‘Export Project Artifacts and Run’.


Select all the artifacts of ‘ShopMeConfigs’ and click on ‘Finish’.

You may see the console results appearing as follows,

Voila! Your ‘ShopMe’ API is up and running. You can open the Monitoring dashboard and see the information about the deployed artifacts. Now you can access the products of all the three Manufacturers via the ShopMeAPI you created!


See you again with more exciting stuff on Integration Solutions!


Happy Integration!


Related Links :

https://wso2.com/integration/integration-studio/

https://wso2.com/integration/micro-integrator/

https://apim.docs.wso2.com/en/latest/integrate/integration-overview/


Also published here.