Skip to content

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"/>

Build and run

Create the artifacts:

  1. Set up WSO2 Integration Studio.
  2. Create an ESB Solution project.
  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 stockquote_service.jar.
  2. Open a terminal, navigate to the location of the downloaded service, and run it (stock quote service) using the following command:

    java -jar stockquote_service.jar

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> Company</ax21:name>