Using a Simple REST API

You can configure REST endpoints in the Micro Integrator by directly specifying HTTP verbs, URL patterns, URI templates, HTTP media types, and other related headers. You can define REST APIs and the associated resources by combining REST APIs with mediation features provided by the underlying messaging framework.

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.

This is a REST API with two API resources. The GET calls are handled by the first resource. These REST calls will get converted into SOAP calls and sent to the back-end service. The response will be sent to the client in POX format.

<api name="StockQuoteAPI" context="/stockquote" xmlns="">
   <resource uri-template="/view/{symbol}" methods="GET">
              <m0:getQuote xmlns:m0="http://services.samples">
              <arg expression="get-property('uri.var.symbol')"/>
         <header name="Action" value="urn:getQuote"/>
              <address uri="http://localhost:9000/services/SimpleStockQuoteService" format="soap11"/>
   <resource methods="POST" url-mapping="/order/*">
         <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
         <property name="OUT_ONLY" value="true"/>
         <header name="Action" value="urn:placeOrder"/>
                <address uri="http://localhost:9000/services/SimpleStockQuoteService" format="soap11"/>

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:

  • Sending a GET request.

    Open a terminal and execute the following command. This sends a simple GET request to the Micro Integrator.


    The Micro Integrator returns the following response to the client.

    <soapenv:Envelope xmlns:soapenv="" xmlns:ns="http://services.samples" xmlns:ax21="http://services.samples/xsd">
                    <ax21:name>IBM Company</ax21:name>
  • Sending a POST request.

    1. Save the following sample request as placeorder.xml in your local file system.

      <placeOrder xmlns="http://services.samples">
    2. Open a terminal, navigate to the location of your placeorder.xml file, and execute the following command. This posts a simple XML request to the Micro Integrator.

      curl -v -d @placeorder.xml -H "Content-type: application/xml"

      The Micro Integrator returns the 202 response back to the client.

      < HTTP/1.1 202 Accepted
      < Date: Wed, 30 Oct 2019 05:33:49 GMT
      < Transfer-Encoding: chunked