Over a million developers have joined DZone.

HTTP Query Parameters on Demand

DZone's Guide to

HTTP Query Parameters on Demand

In this post, a software architect demonstrates how to add query parameters to HTTP calls, using the GET and PUT methods.

· Integration Zone ·
Free Resource

How to Transform Your Business in the Digital Age: Learn how organizations are re-architecting their integration strategy with data-driven app integration for true digital transformation.

In this article, we will see how to add query params on demand. In the HTTP world, the HTTP GET method accepts query parameters as inputs and returns data based on those parameters. But sometimes, when the parameter's value is null, the parameter ends up passing nothing to the GET service. When your requirement is not to create parameters, it is important to know if the value is null.

Usually, HTTP query params can be configured statically in the below way, so that the value is null in the URL. It will be passed as empty, and, as a result, the provider service will return an unexpected result.

Image title

But what will happen if value2 is null? In this case, the URL will look like the below example:


For any HTTP call, we can use Postman so that the parameters can be edited in a table format as a key-value pair. In order to overcome this issue, we can add query.params as a HashMap(#[new java.util.HashMap()]) variable. Hashmap can store key-value pairs, and it can be used inside HTTP connectors.

Once we declare a variable, we can add an expression shape with the below expression:

if(message.inboundProperties.'http.query.params'.param1 != null)
flowVars.params.put("param1", message.inboundProperties.'http.query.params'.param1);

if(message.inboundProperties.'http.query.params'.param2 != null)
flowVars.params.put("param2", message.inboundProperties.'http.query.params'.param2);

if(message.inboundProperties.'http.query.params'.param3 != null)
flowVars.params.put("param3", message.inboundProperties.'http.query.params'.param3);

//if it is a mandatory
flowVars.params.put("api_key", flowVars.apikey);

Here, params is my flow's variable name and, using the put method, we can insert the query parameter. Based on the inbound property's value, we bet the value inserted into theparams  parameter.

The above expression adds param1param2, and param3 as conditionals, and api_key as mandatory.

Now, we can configure this variable in the HTTP connector as shown below.

Image title

Now we are done and the URL with the parameter will look like the below example if param2 is null:


Build and deploy API integrations 7x faster. Try the Cloud Elements 100% RESTful platform for 30 days free. Access your trial here.

mule flow ,integration ,http get ,postman

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}