Playing with Query Params using WSO2 Property Mediator.

We can invoke APIs using a request payload or sending them in the URL as query parameters.

We can do several operations using the property mediator with the query parameters.

We can check this using a simple property as below. Assume my URL is as below. We can check if all these query params exist in the URL. The query params in this URL are name, term, and amount.

http://localhost:8290/api?name=isruu&term=30&amount=250000

You can further read about Query Parameters from this doc.

Let’s look at the following scenario. Assume the user enters the customer name, term, and loan amount in the request as above. As the output, he needs to have calculated the monthly installment amount which should be paid to the bank.

We can access query params as get-property(‘query.param.name’). We can get the boolean value of it as boolean(get-property(‘query.param.name’)).

If the name exists in the URL as query param it will output true else false. We can combine two or more expressions using and operation as shown above.

This can be achieved using XPath functions. To enable XPath functions in WSO2 EI 7 and WSO2 EI 6, please refer to this document.

As per our use case, we need to do a calculation based on the loan term and the loan amount.

monthly installment = round value of ((amount/term)*1.17)/100

It is done in the property mediator as below. As per the use case, I’m doing this in the args expression.

You can refer to the complete XML Configuration as below.

In the above API, first, it checks if all the query parameters exist in the URL. If yes, it will go to the true case in the switch mediator. It will create a Payload using the Payload Factory mediator.

After deploying the API, open any of your browsers and paste the below URL in the tab.

http://localhost:8290/api?name=isruu&term=30&amount=250000

It will provide an output as below.

Bank info for customer isruu about loan amount 250000 EUR in term 30 months: 9750.0 EUR

Senior Software Engineer — QA at WSO2