Skip to content

Handling HTTP Status Codes

A REST service typically sends HTTP status codes with its response. When you configure an API that send messages to a SOAP back-end service, you can set the status code of the HTTP response within the configuration. To achieve this, set the status code parameter within the Out sequence of the API definition.

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.

<api xmlns="" name="StockQuoteAPI" context="/stockquote">`
    <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"/>
            <property name="HTTP_SC" value="201" scope="axis2" />

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:


Send the following request to the Micro Integrator:

curl -v

The response message will contain the following response code (201) and the requeste stock quote information.

< HTTP/1.1 201 Created
< server: ballerina
< Access-Control-Allow-Methods: GET
< content-type: text/plain
< Access-Control-Allow-Headers: 
< Date: Tue, 29 Oct 2019 15:41:05 GMT
< Transfer-Encoding: chunked

The requested stock quote information:

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