<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dimuthu's Blog &#187; REST</title>
	<atom:link href="http://www.dimuthu.org/tag/rest/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dimuthu.org</link>
	<description>Waiting for your comments</description>
	<lastBuildDate>Wed, 21 Dec 2011 05:39:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<image>
  <link>http://www.dimuthu.org</link>
  <url>http://www.dimuthu.org/favicon.ico</url>
  <title>Dimuthu's Blog</title>
</image>
		<item>
		<title>Apache Axis2/C RESTful URL Mapping Algorithm</title>
		<link>http://www.dimuthu.org/blog/2008/11/21/apache-axis2c-restful-url-mapping-algorithm/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/21/apache-axis2c-restful-url-mapping-algorithm/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 10:26:27 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[algorithm]]></category>
		<category><![CDATA[axis2/c]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[time complexity]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=664</guid>
		<description><![CDATA[Few weeks back I wrote a blog post about Writing RESTful Services in C which explain the use of Axis2/C REST API. Basically when you provide a HTTP Method (GET, POST, PUT or DELETE) and a HTTP URL, it is matched with a given HTTP method and a URL pattern in order to identify the [...]]]></description>
			<content:encoded><![CDATA[<p>Few weeks back I wrote a blog post about <a href="http://www.dimuthu.org/blog/2008/10/18/write-restful-services-in-c/">Writing RESTful Services in C</a> which explain the use of <a href="http://ws.apache.org/axis2/c">Axis2/C</a> REST API. Basically when you provide a HTTP Method (GET, POST, PUT or DELETE) and a HTTP URL, it is matched with a given HTTP method and a URL pattern in order to identify the operation and extract out the request parameters. For the example mentioned in the above <a href="http://www.dimuthu.org/blog/2008/10/18/write-restful-services-in-c/">blog</a>, we can summarize the URL mapping like this.</p>
<table border="1">
<tbody>
<tr style="background:#dddddd">
<td>Operation</td>
<td>HTTP Method</td>
<td>URL Pattern</td>
<td>Example Requests</td>
</tr>
<tr>
<td>getSubjects</td>
<td>GET</td>
<td>subjects</td>
<td>GET subjects</td>
</tr>
<tr>
<td>getSubjectInfoPerName</td>
<td>GET</td>
<td>subjects/{name}</td>
<td>GET subjects/maths</td>
</tr>
<tr>
<td>getStudnets</td>
<td>GET</td>
<td>students</td>
<td>GET students</td>
</tr>
<tr>
<td>getStudnetsInfoPerName</td>
<td>GET</td>
<td>students/{name}</td>
<td>GET students/john</td>
</tr>
<tr>
<td>getMarksPerSubjectPerStudent</td>
<td>GET</td>
<td>students/{student}/marks/{subject}</td>
<td>GET students/john/marks/maths</td>
</tr>
</tbody>
</table>
<p>You can watch <a href="http://labs.wso2.org/wsf/php/resource_view.php?url=RESTfulSchool">an application with this URL mapping in live</a>, written using <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> which in fact run Axis2/C algorithms underneath.</p>
<p>Last week I updated this REST mapping algorithm and started a <a href="http://www.nabble.com/REST-URL-Mapping---The-changes-done-in-pattern-matching-Algorithm-to20594898.html#a20594898">discussion about the changes on Axis2/C Dev list</a>. I thought it would be better explain the idea on by blog too.</p>
<p>What the early algorithm (before my changes) did was, it search each pattern in the order it was declared, and returns when a match is found. Sequential searching for a matching pattern can reduce the performance as the number of operations grows. So my solutions was to keep the url pattern in a multi level (recursive) structure and match the url from one level to another.</p>
<p>Here is the structure of the &#8216;c struct&#8217;. (defined in src/core/util/core_utils.c)</p>
<pre class="c"><span style="font-style: italic; color: #808080;">/* internal structure to keep the rest map in a multi level hash */</span>
<span style="color: #993333;">typedef</span> <span style="color: #993333;">struct</span> <span style="color: #66cc66;">{</span>
    <span style="font-style: italic; color: #808080;">/* the structure will keep as many as following fields */</span>

    <span style="font-style: italic; color: #808080;">/* if the mapped value is directly the operation */</span>
    axis2_op_t *op_desc;

    <span style="font-style: italic; color: #808080;">/* if the mapped value is a constant, this keeps a hash map of
    possible constants =&gt; corrosponding map_internal structure */</span>
    axutil_hash_t *consts_map;

    <span style="font-style: italic; color: #808080;">/* if the mapped value is a param, this keeps a hash map of
    possible param_values =&gt; corrosponding_map_internal structre */</span>
    axutil_hash_t *params_map;

<span style="color: #66cc66;">}</span> axutil_core_utils_map_internal_t;</pre>
<p>Here is how it will looks like when the above URL pattern set (shown in the above table) is kept inside this multi-level (recursive) structure.</p>
<pre>svc-&gt;op_rest_map  (hash)
                |
            "GET:students" --------- axutil_core_utils_map_internal_t (instance)
                |                                            |
                |                                        op_desc (axis2_op_t* for "GET students" op)
                |                                            |
                |                                        consts_map (empty hash)
                |                                            |
                |                                        params_map (hash)
                |                                                         |
                |                                                      "{student_id}" ------------- axutil_core_utils_map_internal_t (instance)
                |                                                                                            |
                |                                                                                op_desc (axis2_op_t* for "GET students/{student_id}" op)
                |                                                                                            |
                |                                                                                parms_map (empty hash)
                |                                                                                            |
                |                                                                                 const_map (hash)
                |                                                                                            |
                |                                                                                        "marks" ------------------- axutil_core_utils_map_internal_t (instance)
                |                                                                                                                            |
                |                                                                                                                    op_desc (NULL)
                |                                                                                                                            |
                |                                                                                                                   consts_map (empty hash)
                |                                                                                                                            |
                |                                                                                                                   params_map (hash)
                |                                                                                                                            |
                |                                                                                                                      "{subject_id}" ----------- axutil_core_utils_map_internal_t (instance)
                |                                                                                                                                                                               |
                |                                                                                                                                       op_desc (axis2_op_t* for "GET students/{student_id}/marks/{subject_id}" op)
                |                                                                                                                                                                               |
                |                                                                                                                                                                 consts_map / params_map (Both NULL)
                |
            "GET:students" --------- axutil_core_utils_map_internal_t (instance)
                                                            |
                                                        op_desc (axis2_op_t* for "GET students" op)
                                                            |
                                                        consts_map (empty hash)
                                                            |
                                                        params_map (hash)
                                                            |
                                                      "{student_id}" ------------- axutil_core_utils_map_internal_t (instance)
                                                                                                          |
                                                                                  op_desc (axis2_op_t* for "GET students/{student_id}" op)
                                                                                                          |
                                                                                             consts_map / params_map (Both NULL)</pre>
<p>This structure is build at the time the server initialize the services. (from the &#8220;axis2_svc_get_rest_op_list_with_method_and_location&#8221; function in src/core/description/svc.c)</p>
<p>As each request hit the service, the request HTTP method and the URL is matched (which we call &#8216;rest dispatching&#8217;) with the above structure using the following algorithm. (defined in the &#8220;axis2_rest_disp_find_op&#8221; function in src/core/engine/rest_disp.c). Note that here we are extracting out the user REST parameters as well, but it is not shown in here.</p>
<ol>
<li>The request URL is spitted in to URL components from &#8216;/&#8217; character. Retrive the instance of axutil_core_utils_map_internal_t  from the svc-&gt;rest_map to the varaible &#8216;mapping_struct&#8217;.</li>
<li>Check the existance of URL components, count(URL components) &gt; 0.</li>
<li>If it doesn&#8217;t exist any URL components, get the value of mapping_struct-&gt;op_desc where the mapping_struct is the current mapping instance of axutil_core_utils_map_internal_t. if the mapping_struct-&gt;op_desc is not NULL, we found the operation. If it is NULL just exit returning NULL.</li>
<li>Else If some URL component(s) exist, check the most former URL component in the mapping_struct-&gt;const_map hash. If mapping_struct-&gt;const_map['former_url_component'] is not NULL, assign the mapping struct-&gt;const_map['former_url_component'] value to mapping_struct and follow the step 2 with the remaining URL components. (note that here hash['key'] syntax is used to take the value for the key from the hash &#8216;hash&#8217;. If that returns TRUE, we found the opeartion, if not countine to step5.</li>
<li>if mapping_struct-&gt;const_map['former_url_component'] is NULL, match the former url component with each key (which is a URL component pattern) in mapping_struct-&gt;param_map hash. (We use the function <span> &#8220;axis2_core_utils_match_url_component_with_pattern&#8221; in src/core/util/core_utils.c to</span> map URL component with the URL component pattern<span>). If matching pattern found assign the mapping_struct-&gt;param_map['key'] to mapping struct and </span>follow the step 2 with the remaining URL components. If that returns TRUE for some key it will be the matching operation.</li>
</ol>
<p>Where as the earlier algorithm can be simplified to,</p>
<ol>
<li>Match the request URL with URL patterns of each operation. This will be like calling the function &#8220;<span>axis2_core_utils_match_url_component_with_pattern&#8221; (mentioned in step5 of the above algorithm) for the complete URL rather than for a URL component<br />
</span></li>
<li>If the pattern is matched, matching operation is the selected operation for the request.</li>
</ol>
<p>I approximately calculated the time complexity of both of these algorithm.</p>
<p>Here is the time complexity of the later described algorithm.</p>
<table border="1">
<tbody>
<tr>
<td>Average time complexity of iterating &#8216;n&#8217; number of operations</td>
<td>n/2 = O(n)</td>
</tr>
<tr>
<td>Time complexity of matching pattern with a URL with the length &#8216;p&#8217; (complexity of the &#8216;axis2_core_utils_match_url_component_with_pattern&#8217; function)</td>
<td>O(p^2)</td>
</tr>
<tr style="background:#eeeeee">
<td>Complete time complexity of the algorithm</td>
<td>O(n*p^2)</td>
</tr>
</tbody>
</table>
<p>Time complexity of the formerly described algorithm. (which is currently in the SVN).</p>
<table border="1">
<tbody>
<tr>
<td>Time Complexity of a Hash Search</td>
<td>O(1)</td>
</tr>
<tr>
<td>Average Number of has searches required. This is the average number of levels in the tree of recursive structures drawn above</td>
<td>long(n)/2 = O(log(n))</td>
</tr>
<tr>
<td>Time complexity of matching pattern with a URL component with the average length &#8216;d&#8217;, d &lt; p (p = the length of the complete URL)</td>
<td>O(d^2)</td>
</tr>
<tr>
<td>Number of time pattern matching is required = number of param components in the URL = k, k &lt; p/d (p = the length of the url, d = average length of the URL component)/</td>
<td>k = O(k)</td>
</tr>
<tr style="background:#eeeeee">
<td>Complete time complexity of the algorithm</td>
<td>O(log(n)*d^2*k)</td>
</tr>
</tbody>
</table>
<p>Considering the facts, O(logn) &lt; O(n),d &lt; p and k &lt; p/d we can safely conclude</p>
<p>O(long(n)*d^2*k) &lt; O(n*p^2)  =&gt; The newer algorithm has better (low) time complexity.</p>
<p>However the time complexity is valid only it takes high values for the parameters. For low values  the actual time taken by the newer algorithm can have high values, considering the constant overhead of the recursions and the hash search. So in order to judge the performance of the algorithm, we have to run some test cases and measure the actual times. Possibly a task for the weekend <img src='http://www.dimuthu.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/21/apache-axis2c-restful-url-mapping-algorithm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WSF/PHP Samples Explained</title>
		<link>http://www.dimuthu.org/blog/2008/11/07/wsfphp-samples-explained/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/07/wsfphp-samples-explained/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 12:20:02 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[DataServices]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[beginners]]></category>
		<category><![CDATA[code first]]></category>
		<category><![CDATA[contract first]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[mtom]]></category>
		<category><![CDATA[reliable messaging]]></category>
		<category><![CDATA[samples]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=589</guid>
		<description><![CDATA[Here is a simple categorization of the WSF/PHP samples. You can access all the wsf/php samples from http://labs.wso2.org/wsf/php/solutions/samples/index.html. Sample Category Example Client Source Code Example Service Source Code Online Demo Beginners echo_client.php echo_service.php Demo REST echo_client_rest.php echo_service_with_rest.php Demo WSDL Mode (Contract First) wsdl_11_client.php wsdl_11_service.php Demo WSDL Generation (Code First) doclit_client.php doclit_service.php Demo MTOM Attachments mtom_download_client.php [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a simple categorization of the <a href="http://wso2.org/projects/wsf/php">WSF/PHP </a>samples. You can access all the wsf/php samples from <a href="http://labs.wso2.org/wsf/php/solutions/samples/index.html">http://labs.wso2.org/wsf/php/solutions/samples/index.html</a>.</p>
<table border="1">
<tbody>
<tr style="background:#dddddd">
<td>Sample Category</td>
<td>Example Client Source Code</td>
<td>Example Service Source Code</td>
<td>Online Demo</td>
</tr>
<tr>
<td>Beginners</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fecho_client.php">echo_client.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fecho_service.php">echo_service.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/echo_client.php">Demo</a></td>
</tr>
<tr>
<td>REST</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fecho_client_rest.php">echo_client_rest.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fecho_service_with_rest.php">echo_service_with_rest.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/echo_client_rest.php">Demo</a></td>
</tr>
<tr>
<td>WSDL Mode (Contract First)</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fwsdl_mode%2Fwsdl_11_client.php">wsdl_11_client.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fwsdl_mode%2Fwsdl_11_service.php">wsdl_11_service.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/wsdl_mode/wsdl_11_client.php">Demo</a></td>
</tr>
<tr>
<td>WSDL Generation (Code First)</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fwsdl_generation%2Fdoclit_client.php">doclit_client.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fwsdl_generation%2Fdoclit_service.php">doclit_service.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/wsdl_generation/doclit_client.php">Demo</a></td>
</tr>
<tr>
<td>MTOM Attachments</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fmtom%2Fmtom_download_client.php">mtom_download_client.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fmtom%2Fmtom_download_service.php">mtom_download_service.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/mtom/mtom_download_client.php">Demo</a></td>
</tr>
<tr>
<td>Security</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fsecurity%2Fencryption%2Fclient.php">encryption_client.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Fsecurity%2Fencryption%2Fservice.php">encryption_service.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/security/encryption/client.php">Demo</a></td>
</tr>
<tr>
<td>Reliable Messaging</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Freliable%2Fecho_client_rm.php">echo_client_rm.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2Freliable%2Fecho_service_rm.php">echo_service_rm.php</a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/reliable/echo_client_rm.php">Demo</a></td>
</tr>
<tr>
<td>Data Services</td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2FDataServices%2FCustomerDetailsClient.php">CustomerDetailsClient.php</a><a></a></td>
<td><a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2Fsamples%2FDataServices%2FCustomerDetailsService.php">CustomerDetailsService.php</a><a></a></td>
<td><a href="http://labs.wso2.org/wsf/php/solutions/samples/DataServices/CustomerDetailsClient.php">Demo</a></td>
</tr>
</tbody>
</table>
<p>If you have downloaded the  <a href="http://wso2.org/projects/wsf/php">WSF/PHP binaries or souce code</a> package you can find all these samples, inside the &#8216;samples&#8217; directory</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/07/wsfphp-samples-explained/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Write RESTful Services in C</title>
		<link>http://www.dimuthu.org/blog/2008/10/18/write-restful-services-in-c/</link>
		<comments>http://www.dimuthu.org/blog/2008/10/18/write-restful-services-in-c/#comments</comments>
		<pubDate>Sat, 18 Oct 2008 17:40:14 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[axis2/c]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[services]]></category>
		<category><![CDATA[services.xml]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=497</guid>
		<description><![CDATA[You can write REST as well as SOAP web services using Apache Axis2/C web services framework. There you can make existing Axis2/C web services RESTful just by providing the URL patterns and the HTTP methods to each operation in  the services.xml which act as a simple descriptor for an Axis2/C service. So if we rewrite [...]]]></description>
			<content:encoded><![CDATA[<p>You can write REST as well as SOAP web services using <a href="http://www.dimuthu.org/">Apache Axis2/C</a> web services framework. There you can make existing Axis2/C web services RESTful just by providing the URL patterns and the HTTP methods to each operation in  the services.xml which act as a simple descriptor for an Axis2/C service.</p>
<p>So if we rewrite the <a href="http://labs.wso2.org/wsf/php/demo.php?name=RESTfulSchool&amp;demo=RESTFulSchool/demo_client.php&amp;src=RESTFulSchool">RESTful Demo</a> (Written in PHP) using Axis2/C, the services.xml would be something like following.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;service</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"RESTfulSchool"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- mentioning the service library--&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"ServiceClass"</span> <span style="color: #000066;">locked</span>=<span style="color: #ff0000;">"xsd:false"</span><span style="font-weight: bold; color: black;">&gt;</span></span>RESTfulSchool<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/parameter<span style="font-weight: bold; color: black;">&gt;</span></span></span>

    <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- some description </span></span><span><span><span style="color: #009900;"><span style="font-style: italic; color: #808080;">-</span></span></span></span><span style="color: #009900;"><span style="font-style: italic; color: #808080;">-&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;description<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        The RESTful School demo
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/description<span style="font-weight: bold; color: black;">&gt;</span></span></span>

    <span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- list of operations --&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;operation</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"getSubjects"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"RESTMethod"</span><span style="font-weight: bold; color: black;">&gt;</span></span>GET<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/parameter<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"RESTLocation"</span><span style="font-weight: bold; color: black;">&gt;</span></span>subjects<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/parameter<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/operation<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;operation</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"getSubjectInfoPerName"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"RESTMethod"</span><span style="font-weight: bold; color: black;">&gt;</span></span>GET<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/parameter<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"RESTLocation"</span><span style="font-weight: bold; color: black;">&gt;</span></span>subjects/{name}<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/parameter<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/operation<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;operation</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"getStudents"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"RESTMethod"</span><span style="font-weight: bold; color: black;">&gt;</span></span>GET<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/parameter<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"RESTLocation"</span><span style="font-weight: bold; color: black;">&gt;</span></span>students<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/parameter<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/operation<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;operation</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"getStudentInfoPerName"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"RESTMethod"</span><span style="font-weight: bold; color: black;">&gt;</span></span>GET<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/parameter<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"RESTLocation"</span><span style="font-weight: bold; color: black;">&gt;</span></span>students/{name}<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/parameter<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/operation<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;operation</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"getMarksPerSubjectPerStudent"</span><span style="font-weight: bold; color: black;">&gt;</span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"RESTMethod"</span><span style="font-weight: bold; color: black;">&gt;</span></span>GET<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/parameter<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"RESTLocation"</span><span style="font-weight: bold; color: black;">&gt;</span></span>students/{student}/marks/{subject}<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/parameter<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/operation<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/service<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>We will check how to write the service logic for a operation like &#8220;getMarksPerSubjectPerStudent&#8221;.</p>
<pre class="c">axiom_node_t *
RESTfulSchool_getMarksPerSubjectPerStudent<span style="color: #66cc66;">(</span>
    <span style="color: #993333;">const</span> axutil_env_t * env,
    axiom_node_t * request_payload<span style="color: #66cc66;">)</span>
<span style="color: #66cc66;">{</span>
    axiom_node_t *student_node = <span style="font-weight: bold; color: #000000;">NULL</span>;
    axiom_node_t *subject_node = <span style="font-weight: bold; color: #000000;">NULL</span>;

    <span style="font-style: italic; color: #808080;">/* Extracting out the child nodes from the request */</span>
    student_node = axiom_node_get_first_child<span style="color: #66cc66;">(</span>request_payload, env<span style="color: #66cc66;">)</span>;
    subject_node = axiom_node_get_next_sibling<span style="color: #66cc66;">(</span>student_node, env<span style="color: #66cc66;">)</span>;

    <span style="font-style: italic; color: #808080;">/* now we can write the logic to retrieve the marks
       for the given student and subject and build and
       return the response payload */</span>

    <span style="color: #b1b100;">return</span> response_payload;
<span style="color: #66cc66;">}</span></pre>
<p>As you can see the variables {student} and {subject} given in the services.xml can be easily accessed from your business logic, so we can build the response accordingly.</p>
<p>This way you can build a RESTful web services easily using C language.</p>
<p><a style="cursor: pointer; color: green;"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/10/18/write-restful-services-in-c/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>DEMO on a SOAP and REST Client with PHP</title>
		<link>http://www.dimuthu.org/blog/2008/10/17/demo-on-a-soap-and-rest-client-with-php/</link>
		<comments>http://www.dimuthu.org/blog/2008/10/17/demo-on-a-soap-and-rest-client-with-php/#comments</comments>
		<pubDate>Fri, 17 Oct 2008 16:50:57 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[REST]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[WSClient]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=478</guid>
		<description><![CDATA[Last week I wrote a how to on Writing a SOAP and REST Service with PHP. It shows how to write a single script that enables the SOAP and REST web services interfaces using WSF/PHP. Today I&#8217;m going to show you how you can use WSF/PHP to write clients in both SOAP and REST form. [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I wrote a <a href="http://www.dimuthu.org/blog/2008/10/10/writing-a-simple-rest-and-soap-service-with-php/">how to on Writing a SOAP and REST Service with PHP</a>. It shows how to write a single script that enables the SOAP and REST web services interfaces using <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a>. Today I&#8217;m going to show you how you can use WSF/PHP to write clients in both SOAP and REST form.</p>
<p>For that I use the <a href="http://labs.wso2.org/wsf/php/resource_view.php?url=AmazonClient">Amazon Client Demo</a> hosted in the <a href="http://labs.wso2.org/wsf/php">PHP Web Services Demo Site</a>. With this demo you can do shopping with Amazon using their web services API. It uses <a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2FAmazon%2FAmazonClient.php">a php library (AmazonClient.php) </a>that allows us to connect Amazon using SOAP or REST libraries.</p>
<p>You can see in <a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2FAmazon%2FAmazonClient.php">the library code</a> It is using different values for &#8220;useSOAP&#8221; argument depending on what form of messaging we like to use. Amazon SOAP service uses the SOAP 1.1 and the REST service uses the &#8220;GET&#8221; HTTP method for messaging. We can configure these details as mentioned in the following table.</p>
<table border="1px" style="width:500px">
<tbody>
<tr style="background: #666666">
<td>REST</td>
<td>SOAP</td>
</tr>
<tr>
<td>
<pre class="php"><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
      <span style="color: #ff0000;">"to"</span>=&gt;self::<span style="color: #006600;">AMAZON_REST_ENDPOINT</span>,
      <span style="color: #ff0000;">"HTTPMethod"</span>=&gt;<span style="color: #ff0000;">"GET"</span>,
      <span style="color: #ff0000;">"useSOAP"</span> =&gt; <span style="font-weight: bold; color: #000000;">FALSE</span><span style="color: #66cc66;">)</span></pre>
</td>
<td>
<pre class="php"><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
      <span style="color: #ff0000;">"to"</span>=&gt;self::<span style="color: #006600;">AMAZON_SOAP_ENDPOINT</span>,
      <span style="color: #ff0000;">"useSOAP"</span> =&gt; <span style="color: #ff0000;">"1.1"</span>,
      <span style="color: #ff0000;">"action"</span> =&gt; <span style="color: #ff0000;">"http://soap.amazon.com"</span><span style="color: #66cc66;">)</span></pre>
</td>
</tr>
</tbody>
</table>
<p>Since Amazon requires different request messages for SOAP and REST services, we have to create them separately depending on the request type. But the response returns by the service is same in both cases so we can handle it using the same code.</p>
<p>Here is how ItemLookup operation of the Amazon service is written within the above mentioned constrains.</p>
<pre class="php">    <span style="font-style: italic; color: #808080;">/**
     * ItemLookup
     * @param $ASIN Amaxon Item Id
     * @return associate array consist of the response parameters
     */</span>
    <span style="font-weight: bold; color: #000000;">public</span> <span style="font-weight: bold; color: #000000;">function</span> ItemLookup<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$ASIN</span><span style="color: #66cc66;">)</span>
    <span style="color: #66cc66;">{</span>

        <span style="color: #b1b100;">if</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">is_soap</span><span style="color: #66cc66;">)</span>
        <span style="color: #66cc66;">{</span>
             <span style="color: #0000ff;">$req_payload</span> = &lt;&lt;&lt;XML
                &lt;ItemLookup xmlns=<span style="color: #ff0000;">"http://webservices.amazon.com/AWSECommerceService/2007-10-29"</span>&gt;
                    &lt;SubscriptionId&gt;<span style="color: #66cc66;">{</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">amazon_key</span><span style="color: #66cc66;">}</span>&lt;/SubscriptionId&gt;
                    &lt;ResponseGroup&gt;Medium&lt;/ResponseGroup&gt;
                    &lt;Request&gt;
                        &lt;ItemId&gt;<span style="color: #66cc66;">{</span><span style="color: #0000ff;">$ASIN</span><span style="color: #66cc66;">}</span>&lt;/ItemId&gt;
                        &lt;ReviewPage&gt;<span style="color: #cc66cc;">1</span>&lt;/ReviewPage&gt;
                    &lt;/Request&gt;
                &lt;/ItemLookup&gt;
XML;
        <span style="color: #66cc66;">}</span>
        <span style="color: #b1b100;">else</span>
        <span style="color: #66cc66;">{</span>
             <span style="color: #0000ff;">$req_payload</span> = &lt;&lt;&lt;XML
                &lt;ItemLookup xmlns=<span style="color: #ff0000;">"http://webservices.amazon.com/AWSECommerceService/2007-10-29"</span>&gt;
                    &lt;SubscriptionId&gt;<span style="color: #66cc66;">{</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">amazon_key</span><span style="color: #66cc66;">}</span>&lt;/SubscriptionId&gt;
                    &lt;Service&gt;AWSECommerceService&lt;/Service&gt;
                    &lt;ResponseGroup&gt;Large&lt;/ResponseGroup&gt;
                    &lt;Operation&gt;ItemLookup&lt;/Operation&gt;
                    &lt;ItemId&gt;<span style="color: #66cc66;">{</span><span style="color: #0000ff;">$ASIN</span><span style="color: #66cc66;">}</span>&lt;/ItemId&gt;
                    &lt;ReviewPage&gt;<span style="color: #cc66cc;">1</span>&lt;/ReviewPage&gt;
                &lt;/ItemLookup&gt;
XML;
        <span style="color: #66cc66;">}</span>

        <span style="color: #0000ff;">$ret_message</span> = <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">request</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$req_payload</span><span style="color: #66cc66;">)</span>;

        <span style="color: #0000ff;">$simplexml</span> = <span style="font-weight: bold; color: #000000;">new</span> SimpleXMLElement<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$ret_message</span>-&gt;<span style="color: #006600;">str</span><span style="color: #66cc66;">)</span>;

        <span style="color: #0000ff;">$res</span> = <span style="color: #0000ff;">$simplexml</span>;

        <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$res</span>;
    <span style="color: #66cc66;">}</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/10/17/demo-on-a-soap-and-rest-client-with-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Writing a Simple REST and SOAP Service With PHP</title>
		<link>http://www.dimuthu.org/blog/2008/10/10/writing-a-simple-rest-and-soap-service-with-php/</link>
		<comments>http://www.dimuthu.org/blog/2008/10/10/writing-a-simple-rest-and-soap-service-with-php/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 14:23:25 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[Weather]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=457</guid>
		<description><![CDATA[WSF/PHP enables you to write both REST and SOAP services in PHP from a single script. I have written about how you can expose your Database as a REST and SOAP services in few of my previous posts using the Data Service capability of WSF/PHP. But there can be situations where your service is not [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> enables you to write both REST and SOAP services in PHP from a single script. I have written about how you can expose your Database as a REST and SOAP services in <a href="http://www.dimuthu.org/blog/2008/09/18/do-rest-in-php-php-restful-data-services/">few of my previous posts</a> using the Data Service capability of WSF/PHP. But there can be situations where your service is not based on a Database. For an example it can use results of some calculations, or a mashup calling other services. In that case you will prefer to write the service logic yourself. Here is how you can do it.</p>
<p>Lets think we have weather forecast data (may be from another service) and I want to make a web service using it and make it accessible via both REST and SOAP protocols.</p>
<p>In our demo service we give forecasts of temperature, humidity and some other parameters for a given date. So I expect</p>
<p>SOAP request payload as following.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;weatherReport<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;date<span style="font-weight: bold; color: black;">&gt;</span></span></span>{date}<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/date<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;parameter<span style="font-weight: bold; color: black;">&gt;</span></span></span>{parameter}<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/parameter<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/weatherReport<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>And REST Request will be like</p>
<pre>weatherReport/{date}/forecast/{parameter}</pre>
<p>Note that here parameter can hold values like temperature, humidity or sunset-time.</p>
<p>First we declare our operation and the REST Request Mapping like this,</p>
<pre class="php"><span style="color: #0000ff;">$operations</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"weatherReport"</span> =&gt; <span style="color: #ff0000;">"weather_report"</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$restmap</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"weatherReport"</span> =&gt;
				<a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"HTTPMethod"</span> =&gt;<span style="color: #ff0000;">"GET"</span>,
				      <span style="color: #ff0000;">"RESTLocation"</span> =&gt; <span style="color: #ff0000;">"weatherReport/{date}/forecast/{parameter}"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
<p>When you declare your rest mapping like above , in the service operation you will have the same request XML for both SOAP and REST form like this,</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;weatherReport<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;date<span style="font-weight: bold; color: black;">&gt;</span></span></span>{date}<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/date<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;parameter<span style="font-weight: bold; color: black;">&gt;</span></span></span>{parameter}<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/parameter<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/weatherReport<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>So in your service logic you just handling the request in only above format. You can easily extract out the request parameters using SimpleXML functions and return the corresponding result. So you service operation would be something like this,</p>
<pre class="php"><span style="font-weight: bold; color: #000000;">function</span> weather_report<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$in_message</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>

	<span style="font-style: italic; color: #808080;">// create the simple xml element for the request xml</span>
	<span style="color: #0000ff;">$request_xml</span> = <span style="font-weight: bold; color: #000000;">new</span> SimpleXMLElement<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$in_message</span>-&gt;<span style="color: #006600;">str</span><span style="color: #66cc66;">)</span>;

	<span style="font-style: italic; color: #808080;">// extract out the parameter and the date</span>
	<span style="color: #0000ff;">$date</span> = <span style="color: #0000ff;">$request_xml</span>-&gt;<span style="color: #006600;">date</span>;
	<span style="color: #0000ff;">$parameter</span> = <span style="color: #0000ff;">$request_xml</span>-&gt;<span style="color: #006600;">parameter</span>;

	<span style="font-style: italic; color: #808080;">// It is up to you to retrun the weather data ($result) for the requested date and parameter</span>

	<span style="color: #b1b100;">return</span> <span style="color: #ff0000;">"&lt;response&gt;$result&lt;/response&gt;"</span>;
<span style="color: #66cc66;">}</span></pre>
<p>Finally you create the WSService object with the &#8220;operations&#8221; and &#8220;RESTMapping&#8221; and call its reply method which actually response to the requests.</p>
<pre class="php"><span style="color: #0000ff;">$service</span> = <span style="font-weight: bold; color: #000000;">new</span> WSService<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"operations"</span> =&gt; <span style="color: #0000ff;">$operations</span>, <span style="color: #ff0000;">"RESTMapping"</span> =&gt; <span style="color: #0000ff;">$restmap</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$service</span>-&gt;<span style="color: #006600;">reply</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</pre>
<p>You just created a web service which will handle both SOAP and REST requests.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/10/10/writing-a-simple-rest-and-soap-service-with-php/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>The Design of the Twitter REST API</title>
		<link>http://www.dimuthu.org/blog/2008/09/29/the-design-of-the-twitter-rest-api/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/29/the-design-of-the-twitter-rest-api/#comments</comments>
		<pubDate>Mon, 29 Sep 2008 17:29:45 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=408</guid>
		<description><![CDATA[The REST API for Twitter is very simple to learn and implement. And it has a comprehensive documentation. Here is some selected operations to just to show its design. Note that here userid should be replaced with a valid twitter user id or user name and the format should be changed to the required output [...]]]></description>
			<content:encoded><![CDATA[<p>The REST API for Twitter is very simple to learn and implement. And it has a <a href="http://apiwiki.twitter.com/REST+API+Documentation">comprehensive documentation</a>.</p>
<p>Here is some selected operations to just to show its design. Note that here userid should be replaced with a valid twitter user id or user name and the format should be changed to the required output format (.xml,  json, rss, atom are possible output formats)</p>
<table border="1">
<tbody>
<tr style="background:#cccccc">
<td>Operation</td>
<td>HTTP Verb</td>
<td>URL</td>
<td>Example HTTP Request (Setting username as &#8216;dimuthu&#8217; and the output format as .xml)</td>
</tr>
<tr>
<td>Get public (all users) statuses</td>
<td>GET</td>
<td>http://twitter.com/statuses/public_timeline</td>
<td>GET <a href="http://twitter.com/statuses/public_timeline">http://twitter.com/statuses/public_timeline</a></td>
</tr>
<tr>
<td>Get a user statuses</td>
<td>GET</td>
<td>http://twitter.com/statuses/user_timeline/userid.format</td>
<td>GET <a href="http://twitter.com/statuses/user_timeline/dimuthu.xml">http://twitter.com/statuses/user_timeline/dimuthu.xml</a></td>
</tr>
<tr>
<td>Get a particular status</td>
<td>GET</td>
<td>http://twitter.com/statuses/show/statusid.format</td>
<td>GET <a href="http://twitter.com/statuses/show/938135815.xml">http://twitter.com/statuses/show/938135815.xml</a></td>
</tr>
<tr>
<td>Create a new status</td>
<td>POST</td>
<td>http://twitter.com/statuses/update.format</td>
<td>POST http://twitter.com/statuses/update.xml<br />
Authorization: Basic xxxx<br />
&#8230;&#8230;&#8230;..<br />
&lt;status&gt;my status message&lt;/status&gt;</td>
</tr>
<tr>
<td>Delete a particular status</td>
<td>DELETE/ POST</td>
<td>http://twitter.com/statuses/destroy/statusid.xml</td>
<td>DELETE http://twitter.com/statuses/destroy/939390294.xml<br />
Authorization: Basic xxxx<br />
&#8230;&#8230;&#8230;..</td>
</tr>
</tbody>
</table>
<p>After having look at this API, the first question I had was whether this API is actually RESTful. In RESTful design we expect to map a resource to a URL and do CRUD (Create, Read, Update and Delete) operations using request with different Http Verbs (POST, GET, PUT, DELETE) with that same URL. Look at my blog on <a href="http://www.dimuthu.org/blog/2008/09/27/restful-crud-data-services-demo/">RESTful CRUD Data Services Demo</a> for more clarification.</p>
<p>So if ever the API is designed following the above theory it would have been like this.</p>
<table border="1">
<tbody>
<tr style="background:#cccccc">
<td>Operation</td>
<td>HTTP Request</td>
</tr>
<tr>
<td>Get all statuses</td>
<td>GET http://twitter.com/statuses.xml</td>
</tr>
<tr>
<td>Get a particular user statuses</td>
<td>GET http://twitter.com/users/{user_id}/statuses.xml</td>
</tr>
<tr>
<td>Get a particular statuses of a user</td>
<td>GET http://twitter.com/users/{user_id}/statuses/{status_id}.xml</td>
</tr>
<tr>
<td>Crete a particular statuses of a user</td>
<td>POST http://twitter.com/users/{user_id}/statuses.xml</td>
</tr>
<tr>
<td>Update a particular statuses of a user</td>
<td>PUT http://twitter.com/users/{user_id}/statuses/{status_id}.xml</td>
</tr>
<tr>
<td>Delete a particular statuses of a user</td>
<td>DELETE http://twitter.com/users/{user_id}/statuses/{status_id}.xml</td>
</tr>
</tbody>
</table>
<p>So I think although Twitter API is really nice and easy, it is not really a RESTful API. If it was really RESTful, URLs might have been more organized so more easier to remember or predict. But still this API allows thousands of third party application to talk to the twitter, demonstrating the value of  providing web services over just providing some web pages in a website.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/29/the-design-of-the-twitter-rest-api/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>RESTful CRUD Data Services Demo</title>
		<link>http://www.dimuthu.org/blog/2008/09/27/restful-crud-data-services-demo/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/27/restful-crud-data-services-demo/#comments</comments>
		<pubDate>Sat, 27 Sep 2008 09:35:00 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[DataServices]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[applications]]></category>
		<category><![CDATA[CRUD]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[DataService]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=391</guid>
		<description><![CDATA[When you are developing Web Service for CRUD (Create, Read, Update, Delete) operations you may find it is easy to implement it as RESTful service. In this Demo on RESTful CRUD Service You can have an idea how you develop such a service with WSO2 WSF/PHP. Here we take a scenario of submitting applications (say [...]]]></description>
			<content:encoded><![CDATA[<p>When you are developing Web Service for CRUD (<strong>C</strong>reate, <strong>R</strong>ead,  <strong>U</strong>pdate, <strong>D</strong>elete) operations you may find it is easy to implement it as RESTful service. In this <a href="http://labs.wso2.org/wsf/php/resource_view.php?url=RESTFulCRUD">Demo on RESTful CRUD Service</a> You can have an idea how you develop such a service with <a href="http://wso2.org/projects/wsf/php">WSO2 WSF/PHP</a>.</p>
<p>Here we take a scenario of submitting applications (say for a school).</p>
<p>In RESTful world we map a resource to a unique URL. In this demo, application is a resource. We use the URL &#8220;application/{id}&#8221; to represent a particular application with the id {id}.</p>
<p>You can  use  HTTP verb + Resource URL touples to manipulate the resource with CRUD operations.  Here is how it is done in this particular demonstration.</p>
<table border="1">
<tbody>
<tr style="background-color:#CCCCCC;">
<td>Request format (HTTP Verb + URL)</td>
<td>Operation Semantic</td>
</tr>
<tr>
<td>POST applications/{id}</td>
<td>Create an application</td>
</tr>
<tr>
<td>GET applications/{id}</td>
<td>Get an application</td>
</tr>
<tr>
<td>PUT applications/{id}</td>
<td>Change an application</td>
</tr>
<tr>
<td>DELETE applications/{id}</td>
<td>Delete an application</td>
</tr>
</tbody>
</table>
<p>Go for the <a href="http://labs.wso2.org/wsf/php/demo.php?name=RESTFulCRUD&amp;demo=CRUDApplications/demo_client.php&amp;src=./CRUDApplications">wsf/php demo site</a>for the live demo of this service. Visit the <a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2F.%2FCRUDApplications%2Fschool_applications.php">demo service source code</a> to see how easy to implement it with WSF/PHP Data Services library.</p>
<p>I wrote a similar <a href="http://www.dimuthu.org/blog/2008/09/18/do-rest-in-php-php-restful-data-services/">blog on Data Services</a> last week to demonstrate how you design the mapping of url to different resources in a RESTful Service.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/27/restful-crud-data-services-demo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Do REST in PHP &#8211; PHP RESTful Data Services</title>
		<link>http://www.dimuthu.org/blog/2008/09/18/do-rest-in-php-php-restful-data-services/</link>
		<comments>http://www.dimuthu.org/blog/2008/09/18/do-rest-in-php-php-restful-data-services/#comments</comments>
		<pubDate>Thu, 18 Sep 2008 18:04:49 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[DataServices]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[DataService]]></category>
		<category><![CDATA[DELETE]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[POST]]></category>
		<category><![CDATA[PUT]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[ROA]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[WOA]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=293</guid>
		<description><![CDATA[In RESTful paradigm we give a piece of data ( or in other word &#8216;Resource&#8217;) a unique URL. And in order to manipulate data we use HTTP verbs POST/PUT (create, update), GET (read), DELETE (delete). For an example take the scenario of manipulating Students data in a high school. Here is how each operation is [...]]]></description>
			<content:encoded><![CDATA[<p>In RESTful paradigm we give a piece of data ( or in other word &#8216;Resource&#8217;) a unique URL. And in order to manipulate data we use HTTP verbs POST/PUT (create, update), GET (read), DELETE (delete). For an example<br />
take the scenario of manipulating Students data in a high school. Here is how each operation is mapped to a http request (URL + HTTP verb)</p>
<table border="1">
<tbody>
<tr style="background-color:#cccccc">
<td>HTTP request</td>
<td>Operation</td>
</tr>
<tr>
<td>POST api/students/ben</td>
<td>Create the resource (peice of data) called ben as a student. HTTP body or the url itself (e.g. api/students/ben?age=15&amp;country=xx) may contain the required information about ben</td>
</tr>
<tr>
<td>GET api/students/ben</td>
<td>Retrieve the information about ben.</td>
</tr>
<tr>
<td>PUT api/students/ben</td>
<td>Update ben</td>
</tr>
<tr>
<td>DELETE api/student/ben</td>
<td>Delete the student called &#8216;ben&#8217;.</td>
</tr>
</tbody>
</table>
<p>With the addition of all these HTTP verbs <a href="http://wso2.org/projects/wsf/php">WSO2 WSF/PHP 2.0.0</a> become a great tool for RESTful developers. Specially with the introducing Data Services library it was so easy to make your database a REST service. I m thinking of preparing a series of application to demonstrate the power of WSF/PHP with all these new features.</p>
<p>This demo -<a href="http://labs.wso2.org/wsf/php/demo.php?name=RESTfulSchool&amp;demo=RESTFulSchool/demo_client.php&amp;src=RESTFulSchool">RESTful School</a>- shows  how you map a URL to a peice of data. Here we use only the http &#8220;GET&#8221; method (which is the most to used in practicle data service).</p>
<p>Here is some description of the operations you find in there. Just check <a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2FRESTFulSchool%2Fschool_service.php"> the source code for RESTful School demo</a> to see how this is done in code level.</p>
<table border="1">
<tbody>
<tr style="background-color:#cccccc">
<td>Operation</td>
<td>URL</td>
<td>SQL Query</td>
<td>Note</td>
</tr>
<tr>
<td>Get All subjects</td>
<td>
<pre><span style="color: #ff0000;">subjects</span></pre>
</td>
<td>
<pre><span style="color: #ff0000;">SELECT subjectName, subjectTeacher FROM Subjects</span></pre>
</td>
<td>With no parameters</td>
</tr>
<tr>
<td>Get subject information From Name</td>
<td>
<pre><span style="color: #ff0000;">subjects/{name}</span></pre>
</td>
<td>
<pre><span style="color: #ff0000;">SELECT subjectName, subjectTeacher FROM Subjects where SubjectName = ?</span></pre>
</td>
<td>The single parameter feed from prepared statement syntax</td>
</tr>
<tr>
<td>Get All students</td>
<td>
<pre><span style="color: #ff0000;">students</span></pre>
</td>
<td>
<pre><span style="color: #ff0000;">SELECT * FROM Students</span></pre>
</td>
<td>Again no parameters</td>
</tr>
<tr>
<td>Get students From Name</td>
<td>
<pre><span style="color: #ff0000;">students/{name}</span></pre>
</td>
<td>Inner Query:</p>
<pre><span style="color: #ff0000;">SELECT subjectName, marks FROM Marks m, Subjects s "</span>.
        <span style="color: #ff0000;">" where m.studentId = ? and m.subjectID = s.subjectId
</span></pre>
<p>Outer Query</p>
<pre><span style="color: #ff0000;">SELECT * FROM Students where StudentName = ?</span></pre>
</td>
<td>Nested query, Inner query is called from outer query</td>
</tr>
<tr>
<td>Get Marks per Students per Subjects</td>
<td>
<pre><span style="color: #ff0000;">students/{student}/</span><span><span style="color: #ff0000;">marks/</span></span><span style="color: #ff0000;">{subject}</span></pre>
</td>
<td>
<pre><span style="color: #ff0000;">SELECT marks FROM Marks, Subjects, Students where StudentName = ?"</span>.
        <span style="color: #ff0000;">" and SubjectName = ? and Marks.subjectId = Subjects.subjectId"</span>.
        <span style="color: #ff0000;">" and Marks.studentID = Students.StudentId;</span></pre>
</td>
<td>Two parameters, and &#8216;?&#8217; in the sql query..</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/09/18/do-rest-in-php-php-restful-data-services/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

