<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
  ~  Copyright (c) 2009, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
  ~
  ~  WSO2 Inc. licenses this file to you under the Apache License,
  ~  Version 2.0 (the "License"); you may not use this file except
  ~  in compliance with the License.
  ~  You may obtain a copy of the License at
  ~
  ~    http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~  Unless required by applicable law or agreed to in writing,
  ~  software distributed under the License is distributed on an
  ~  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  ~  KIND, either express or implied.  See the License for the
  ~  specific language governing permissions and limitations
  ~  under the License.
  -->

<!DOCTYPE html
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta content="text/html; charset=iso-8859-1" http-equiv="content-type"/>
  <title>WSO2 EI - REST API Samples </title>
</head>

<body>
<h1>Running the REST API Samples with WSO2 Enterprise Integrator (EI)</h1>
<h2><a name="Sample800">Sample 800: Introduction to REST API</a> </h2>
<pre xml:space="preserve">&lt;!-- An empty flat synapse configuration shipped with the WSO2 EI --&gt;
&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

    &lt;!-- You can add any flat sequences, endpoints, etc.. to this synapse.xml file if you do
    *not* want to keep the artifacts in several files --&gt;
&lt;api name="StockQuoteAPI" context="/stockquote"&gt;
   &lt;resource uri-template="/view/{symbol}" methods="GET"&gt;
      &lt;inSequence&gt;
         &lt;payloadFactory&gt;
	    &lt;format&gt;
		&lt;m0:getQuote xmlns:m0="http://services.samples"&gt;
	            &lt;m0:request&gt;
        	       &lt;m0:symbol&gt;$1&lt;/m0:symbol&gt;
	            &lt;/m0:request&gt;
        	 &lt;/m0:getQuote&gt;
	    &lt;/format&gt;
	    &lt;args&gt;
		&lt;arg expression="get-property('uri.var.symbol')"/&gt;
	    &lt;/args&gt;
	 &lt;/payloadFactory&gt;
	 &lt;send&gt;
	    &lt;endpoint&gt;
		&lt;address uri="http://localhost:9000/services/SimpleStockQuoteService" format="soap11"/&gt;
	    &lt;/endpoint&gt;
	 &lt;/send&gt;
      &lt;/inSequence&gt;
      &lt;outSequence&gt;
	 &lt;send/&gt;
      &lt;/outSequence&gt;
   &lt;/resource&gt;
   &lt;resource url-pattern="/order/*" methods="POST"&gt;
      &lt;inSequence&gt;
        &lt;property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/&gt;
	&lt;property name="OUT_ONLY" value="true"/&gt;
	&lt;send&gt;
            &lt;endpoint&gt;
                &lt;address uri="http://localhost:9000/services/SimpleStockQuoteService" format="soap11"/&gt;
            &lt;/endpoint&gt;
         &lt;/send&gt;
      &lt;/inSequence&gt;      
   &lt;/resource&gt;
&lt;/api&gt;
&lt;/definitions&gt;</pre>

<p><strong>Objective: Introduction to REST API</strong> </p>

<p><strong>Prerequisites:</strong><br />
Start the Axis2 server and deploy the SimpleStockQuoteService <br />
Start the Synapse configuration numbered 800: i.e. wso2EI-samples -sn 800<br />
You might need a REST client like curl to test this</p>
<pre xml:space="preserve">curl -v http://127.0.0.1:8280/stockquote/view/IBM</pre>
<pre xml:space="preserve">curl -v http://127.0.0.1:8280/stockquote/view/MSFT</pre>

<p>The above GET calls will be handled by the first resource in the StockQuoteAPI. These REST calls will get converted into SOAP calls and will be sent to the Axis2 server. Response will be sent to the client in POX format. </p>

<p>The following command POSTs a simple XML to the EI. Save following sample place order request as  "placeorder.xml" file in your local file system and execute the command. That is used to invoke a SOAP service. EI returns the 202 response back to the client.</p>

<pre xml:space="preserve">curl -v -d @placeorder.xml -H "Content-type: application/xml" http://127.0.0.1:8280/stockquote/order/</pre>

<pre xml:space="preserve">
&lt;placeOrder xmlns="http://services.samples"&gt;
  &lt;order&gt;
     &lt;price&gt;50&lt;/price&gt;
     &lt;quantity&gt;10&lt;/quantity&gt;
     &lt;symbol&gt;IBM&lt;/symbol&gt;
  &lt;/order&gt;
&lt;/placeOrder&gt;
</pre>

</body>
</html>
