Setting Query Parameters on Outgoing Messages

REST clients use query parameters to provide inputs for the relevant operation. These query parameters may be required to carry out the back-end operations either in a REST service or a proxy service.

Shown below is an example request that uses query parameters.

curl -v -X GET "http://localhost:8290/stockquote/view/IBM?param1=value1&param2=value2"

Synapse configuration

Following is a sample REST API configuration that we can used to implement this scenario. See the instructions on how to build and run this example.

There are two query parameters (customer name and ID) that must be set in the outgoing message from the Micro Integrator. We can configure the API to set those parameters as shown below. The query parameter values can be accessed through the get-property function by specifying the parameter number as highlighted in the request (given above).

<api xmlns="" name="StockQuoteAPI" context="/stockquote">
   <resource methods="GET" uri-template="/view/{symbol}">
         <payloadFactory media-type="xml">
               <m0:getQuote xmlns:m0="http://services.samples">
               <arg evaluator="xml" expression="get-property('uri.var.symbol')"/>
               <arg evaluator="xml" expression="get-property('query.param.param1')"/>
               <arg evaluator="xml" expression="get-property('query.param.param2')"/>
         <property name="SOAPAction" value="urn:getQuote" scope="transport"/>
               <address uri="http://localhost:9000/services/SimpleStockQuoteService" format="soap11"/>

Reading a query or path parameter

You can define a REST API and access the query parameters or path parameters by defining them in expressions. The following is a sample code that shows how the resource is defined.

<resource methods="GET" uri-template="/{val1}/groups/{val2}/json?q1={v1}&q2={v2}">

Reading a query parameter

The following sample indicates how the expressions can be defined using get-property('') to read a query parameter.

<property name="queryParam" expression="get-property('query.param.q1')"></property>

Alternately, you can use the following.

<property name="queryParam" expression="$url:q1"></property>

Reading a path parameter

The following sample indicates how the expressions can be defined using get-property('uri.var.yyy') to read a path parameter.

<property name="pathParam" expression="get-property('uri.var.val1')"></property>

Build and run

Create the artifacts:

  1. Set up WSO2 Integration Studio.
  2. Create an integration project with an ESB Configs module and an Composite Exporter.
  3. Create the REST API with the configurations given above.
  4. Deploy the artifacts in your Micro Integrator.

Set up the back-end service:

  1. Download the back-end service.
  2. Extract the downloaded zip file.
  3. Open a terminal, navigate to the axis2Server/bin/ directory inside the extracted folder.
  4. Execute the following command to start the axis2server with the SimpleStockQuote back-end service:


Invoke the sample API by executing the following command:

curl -v -X GET "http://localhost:8290/stockquote/view/IBM?param1=value1&param2=value2"

You will receive the following response:

        <ax21:name>IBM Company</ax21:name>