<?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; RESTful</title>
	<atom:link href="http://www.dimuthu.org/catagory/rest/restful-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>WSO2 Releases Web Service Framework For C++</title>
		<link>http://www.dimuthu.org/blog/2009/07/29/wso2-releases-web-service-framework-for-cpp/</link>
		<comments>http://www.dimuthu.org/blog/2009/07/29/wso2-releases-web-service-framework-for-cpp/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 02:15:53 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/c++]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[WS-*]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=1013</guid>
		<description><![CDATA[WSO2 announced the release of the Web Services Framework for C++ (WSF/C++) version 2.0.0. Similar to WSF/PHP which is really popular among the PHP community, WSF/CPP is the C++ language binding for the Apache Axis2/C and the other supporting web services projects like Apache Sandesha/C, Apache Rampart/C. With this release C++ developers will be able [...]]]></description>
			<content:encoded><![CDATA[<p>WSO2 announced the release of the <a href="http://wso2.org/projects/wsf/cpp">Web Services Framework for C++ (WSF/C++)</a> version 2.0.0. Similar to <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> which is really popular among the PHP community, WSF/CPP is the C++ language binding for the Apache Axis2/C and the other supporting web services projects like Apache Sandesha/C, Apache Rampart/C.</p>
<p>With this release C++ developers will be able to write web services and web service clients to inter-op with .NET/Java/PHP or any other platform built-on web service standards. The release is shiped with a code generation tool that will be used to generate the code for skeletons and stubs from a WSDL, so developers only need to concentrate on their business logic as the generated code will take care of building or parsing xmls and running them on top of the framework.<br />
Here are the key features of the new release.</p>
<ol>
<li>Support core web service standards like SOAP 1.1, SOAP 1.2, WSDL 1.1, WSDL 2.0, REST</li>
<li>Support for web services QoS specifications.
<ul>
<li>WS-Addressing</li>
<li>WS-Security</li>
<li>WS-Policy</li>
<li>WS-Security-Policy</li>
<li>WS-Reliable-Messaging</li>
</ul>
</li>
<li>Support binary attachment with MTOM and SWA (With the Support for large binaries)</li>
<li>Code generation tool.</li>
<li>Proven interoperability with .NET.</li>
</ol>
<p>As a side note, you will be able to participate to a free summer school training session on the WSF/CPP conducted by<a href="http://nandikajayawardana.blogspot.com/"> Nandika Jayawardane</a> who is the project lead of both WSF/CPP and WSF/PHP on 30th July. You can register to it (for free) from <a href="http://wso2.org/training/cpp_in_soa">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2009/07/29/wso2-releases-web-service-framework-for-cpp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Article Introducing PHP Data Services</title>
		<link>http://www.dimuthu.org/blog/2009/01/05/article-introducing-php-data-services/</link>
		<comments>http://www.dimuthu.org/blog/2009/01/05/article-introducing-php-data-services/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 13:06:55 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[DataServices]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[SQL]]></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[xml]]></category>
		<category><![CDATA[introduction]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[WS-*]]></category>
		<category><![CDATA[ws-security]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=900</guid>
		<description><![CDATA[Now you can view the article I wrote titling &#8220;Introduction to PHP Data Services&#8220;. There I explain how you can design and implement Data Services in PHP using WSF/PHP Data Services Library. This article covers, Designing your Data Service API. Writing the Data Service. Deploying and Testing Data Service. Make the Data Service available in [...]]]></description>
			<content:encoded><![CDATA[<p>Now you can view the article I wrote titling &#8220;<a href="http://wso2.org/library/articles/introduction-php-data-services">Introduction to PHP Data Services</a>&#8220;. There I explain how you can design and implement Data Services in PHP using <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> Data Services Library.</p>
<p>This article covers,</p>
<ol>
<li>Designing your Data Service API.</li>
<li>Writing the Data Service.</li>
<li>Deploying and Testing Data Service.</li>
<li>Make the Data Service available in both SOAP and RESTful form.</li>
<li>Use of WS-* features in your Data Service.</li>
</ol>
<p>If you are thinking of adapting SOA in to your database backed PHP applications, this article will be a good starting point.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2009/01/05/article-introducing-php-data-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RESTful PHP Web Services &#8211; Book Review</title>
		<link>http://www.dimuthu.org/blog/2009/01/01/restful-php-web-services-book-review/</link>
		<comments>http://www.dimuthu.org/blog/2009/01/01/restful-php-web-services-book-review/#comments</comments>
		<pubDate>Thu, 01 Jan 2009 05:22:46 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[design]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[review]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[Book]]></category>
		<category><![CDATA[clients]]></category>
		<category><![CDATA[services]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=865</guid>
		<description><![CDATA[PHP is one of the famous choice, when it comes to develop a web site. As the web evolve with the emerge of web service, REST (REpresentational State Transfer) concepts, the PHP language is also adapted to the new requirements specially with the availability of new SOA (Service Oriented Architecture), REST frameworks and libraries. Anyway [...]]]></description>
			<content:encoded><![CDATA[<p>PHP is one of the famous choice, when it comes to develop a web site. As the web evolve with the emerge of web service, REST (REpresentational State Transfer) concepts, the PHP language is also adapted to the new requirements specially with the availability of new SOA (Service Oriented Architecture), REST frameworks and libraries. Anyway there were hardly any guides, references or samples that properly describe the methodologies of developing REST applications using PHP.</p>
<p>The book &#8220;<a href="http://www.packtpub.com/restful-php-web-services/book">RESTful PHP Web Services</a>&#8216; by <a href="http://samisa-abeysinghe.blogspot.com/">Samisa Abeysinghe</a> certainly fill this gap. It can be used as a step by step guideline for newbies to learn the concepts and write simple RESTful PHP applications and Mashups. And even experienced developers would find this a great reference to keep nearby while working with RESTful Web Services in PHP. And it has lot of code samples, utility functions that developers can use it in their applications.</p>
<p><a href="http://www.packtpub.com/restful-php-web-services/book"><img title="RESTful PHP Web Services - Samisa Abeysinghe" src="http://images.packtpub.com/images/full/1847195520.jpg" alt="RESTful PHP Web Services - Samisa Abeysinghe" width="200" /></a></p>
<p><strong>About the Author</strong></p>
<p><a href="http://samisa-abeysinghe.blogspot.com/">Samisa Abeysinghe</a> is a well recognized name in the web services world. He lead the development of <a href="http://ws.apache.org/axis2/c/">Apache Axis2/C</a> and <a href="http://wso2.org/projects/wsf/php">WSO2 WSF/PHP</a>, two famous open source web service frameworks for &#8216;C&#8217; and PHP. In addition to his deep knowledge in the subject, his experience in involving with the community and the enterprise for years and working as a lecturer in universities, should have influenced a lot in writing this book.</p>
<p><strong>The Arrangement and the Content</strong></p>
<p>The <a href="http://www.packtpub.com/article/restful-php-web-services-table-of-contents">arrangement of the book</a> is done really well to make sure the reader can go through it in the right sequence. All the content is bundled just within 200 pages. So you don&#8217;t need to allocate a lot of time to go through the whole book. It is organized into 7 chapters and two appendixes which are mostly independent from each other.</p>
<p>The first chapter is completely devoted to explain the concepts of RESTful web services. It basically explains what is RESTful web service and why it is needed. And it briefly mentions about the currently available REST Frameworks for PHP.</p>
<p>The second chapter introduce some PHP codes that do REST web service requests and handles the XML responses using both DOM and SimpleXML APIs. And in the third chapter it shows more code samples specially about consuming real world web services like BBC, Yahoo and an earthquakes information service. Theses codes are written as mashups mostly combining two services to produce more meaningful information.</p>
<p>The forth chapter is about  designing and writing web service providers. Its counterpart, writing web service consumers is described in the chapter five. There it demonstrate a library system that operate using RESTful webservices. You can map this example to any system that you may like to develop to run with RESTful web services.  The chapter five of the book is available as a free download, <a href="http://www.dimuthu.org/wp-content/uploads/2008/12/restful-php-webservices_sample-chapter.pdf">RESTful PHP Web Services &#8211; Chapter 5</a>.</p>
<p>The forth and fifth chapters are not using any framework to write the sample codes on consuming and providing web services. But in the sixth chapter it shows the use of <a href="http://framework.zend.com/">Zend framework</a> to do write them. There it rewrites the same example (The RESTful library system) in MVC (Model -View &#8211; Controller) approach using the functionalities of Zend framework. (In fact the View in the service is omitted).</p>
<p>The seventh chapter is about debugging web services. Debugging is a much needed step in any software development cycle. So if you are a newbie, you should read this chapter before start writing any of your own code. This introduces tools and methodologies to make your debugging easy and effective.</p>
<p>The book contains two appendixes. They are too really useful as the chapters of the book. In the first appendix it explains another REST web service framework, <a href="http://wso2.org/projects/wsf/php">WSO2 Web Services Framework for PHP (WSF/PHP)</a>. To demonstrate it uses, some selected functionalities of the example library system (that is mentioned in chapters 4, 5, 6) is re-implemented using WSF/PHP. And it shows you how you can convert this RESTful system to a SOAP system in a minute. The second appendix provides you a code of a class (RESTClient), that you can use in consuming web services very effectively.</p>
<p><strong>Recommended Readers<br />
</strong></p>
<p>This book assume you have some knowledge in PHP. But it doesn&#8217;t require you to know anything related to web services, REST or XML. As you read the first few chapters, you will have a good understanding on the concepts and the basic applications of REST and XML using PHP. And the later chapters will guide to get deeper knowledge in writing complex and real world applications.</p>
<p>If you are a professional developer, you can skip the introduction chapters and jump directly to where you need to refer. For an example, if you use this book as a reference in designing and developing RESTful web service providers, you can directly read the chapter4 &#8211; Resource Oriented Services, chapter6- Resource Oriented Clients and Services with Zend Framework and probably the chapter 7 &#8211; Debugging Web Services.</p>
<p>This book contains the same example system (the library system) written in three different approaches, first without using any framework support, second using the Zend Framework, third using WSF/PHP. Each of them has its own pros and cons. So if you want to determine the approach more suitable to your requirements, or thinking of migrating from one to another, this book will be an ideal resource for you.</p>
<p>As you may have already noticed, this book contains lot of code samples. All the concepts are followed by simple code samples that explain the concept. In appendix it gives you a complete code for RESTClient class that you can use to call any REST service. Apart from the code of the example library system written using different frameworks, it has lot of codes for calling public web service APIs. And the explanation of the code is also done really well.</p>
<p>So it is clear this book is more targetting readers who like to implement PHP RESTful Systems in practice. And it covers enough concepts that you needed to know in writing practicle applications. So this book can take you from the zero knowlege to a deeper knowlege of RESTful PHP Web Services.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2009/01/01/restful-php-web-services-book-review/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<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>RESTful URL Mapping in WSF/PHP</title>
		<link>http://www.dimuthu.org/blog/2008/11/16/restful-url-mapping-in-wsfphp/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/16/restful-url-mapping-in-wsfphp/#comments</comments>
		<pubDate>Sun, 16 Nov 2008 17:21:49 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[DataServices]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[SQL]]></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[RESTfulSchool]]></category>
		<category><![CDATA[URL Mapping]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=621</guid>
		<description><![CDATA[In a RESTful design, choose of URLs for resources are really important. The URL uniquely represents a resource. Service consumers can change some parts in the URL to access different other resources. So it is clear that the URL consists of some constant parts which describe the resource group or catalog in general and some [...]]]></description>
			<content:encoded><![CDATA[<p>In a RESTful design, choose of URLs for resources are really important. The URL uniquely represents a resource. Service consumers can change some parts in the URL to access different other resources. So it is clear that the URL consists of some constant parts which describe the resource group or catalog in general and some variable parts which have different and unique values for different resources.</p>
<p>As an example look at the following URL patterns</p>
<ul>
<li>students/{name} &#8211; The constant &#8216;students&#8217; represent the students group in general and the variable &#8216;name&#8217; is used to identify each student individually.</li>
<li>students/{name}/marks/{subject} &#8211; The constants &#8216;students&#8217; and &#8216;marks&#8217; shows that this resource is a marks of some students, The two variables &#8216;name&#8217; and &#8216;subjects&#8217; addresses which student and marks of which subject is presented in the URL.</li>
</ul>
<p>You can have a look at some of the uses of such mappings from <a href="http://labs.wso2.org/wsf/php/resource_view.php?url=RESTfulSchool">RESTful School demo</a>.</p>
<p><a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> allows you to create RESTful Web Services and further more RESTful Data Services in PHP.</p>
<p>In a RESTful Data Service you expose a database query as a web service. There you can write a prepared statement and feed arguments for the statement through the variable parameters of the URL. For an example take the <a href="http://labs.wso2.org/wsf/php/source_page_old.php?src=solutions%2FRESTFulSchool%2Fschool_service.php">RESTfulSchool Demo Code</a>.</p>
<p>To retrieve a particular student, we can use the following prepared statement and the URL pattern ( This URL Pattern+  HTTP &#8216;GET&#8217; method is matched to execute this query. )</p>
<pre class="php"><span style="color: #0000ff;">$sql</span> = <span style="color: #ff0000;">"SELECT * FROM Students where StudentName = ?"</span>

<span style="color: #0000ff;">$get_students_with_name_url</span> = <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;">"students/{name}"</span><span style="color: #66cc66;">)</span>;</pre>
<p>So you can execute this prepared statement with the subject name &#8216;John&#8217; using the following URL.</p>
<pre><a href="http://labs.wso2.org/wsf/php/solutions/RESTFulSchool/school_service.php/students/john">http://labs.wso2.org/wsf/php/solutions/RESTFulSchool/school_service.php/students/john</a></pre>
<p>If your service is not exposing the database directly, then you have to choose the general web service API rather than the data service specific API. In there you will be able to write your business logic for publishing student information in a PHP function and expose it as a web service.</p>
<p>In such a cas,e your function is taking an argument which of type <a href="http://wso2.org/project/wsf/php/2.0.0/docs/api_content.html#message">WSMessage</a>. This structure hold an XML that contains values for all the variable parameters as in the users request URL. For an example for above REST Mapping, we can expect the following XML.</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;getSubject<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;name<span style="font-weight: bold; color: black;">&gt;</span></span></span>Chemistry<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/getSubject<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
<p>And your function to expose as a service, would be look like this,</p>
<pre class="php"><span style="font-weight: bold; color: #000000;">function</span> getSubject<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$input</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
    <span style="font-style: italic; color: #808080;">/* retrieve the subject name from the
       $input xml using simple xml */</span>

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

    <span style="color: #0000ff;">$subject_name</span> = <span style="color: #0000ff;">$input</span>-&gt;<span style="color: #006600;">name</span>;

    <span style="font-style: italic; color: #808080;">/* write the logic to retrieve subject information
      for the $subject_name */</span>

    ....
<span style="color: #66cc66;">}</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/16/restful-url-mapping-in-wsfphp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Book on RESTful PHP Web Services</title>
		<link>http://www.dimuthu.org/blog/2008/10/21/book-on-restful-php-web-services/</link>
		<comments>http://www.dimuthu.org/blog/2008/10/21/book-on-restful-php-web-services/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 18:01:52 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[Book]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=531</guid>
		<description><![CDATA[Samisa Abeysinghe who is the director of engineering at WSO2 and one of the key leaders of the WSF/PHP project has published a book titled RESTful PHP Web Services. In Samisa&#8217;s Blog He describes the structure and the content of the book in his own words. If you are developing RESTful web services in PHP, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://samisa-abeysinghe.blogspot.com/">Samisa Abeysinghe </a>who is the director of engineering at WSO2 and one of the key leaders of the <a href="http://wso2.org/projects/wsf/php">WSF/PHP project</a> has published a book titled <a href="http://www.packtpub.com/restful-php-web-services/book">RESTful PHP Web Services</a>.</p>
<div class="wp-caption aligncenter" style="width: 550px"><a href="http://www.packtpub.com/restful-php-web-services/book"><img title="RESTful PHP Web Services - Samisa Abeysinghe" src="http://images.packtpub.com/images/full/1847195520.jpg" alt="RESTful PHP Web Services - Samisa Abeysinghe" width="540" height="666" /></a><p class="wp-caption-text">RESTful PHP Web Services - Samisa Abeysinghe</p></div>
<p>In <a href="http://samisa-abeysinghe.blogspot.com/2008/10/restful-php-web-services-book.html">Samisa&#8217;s Blog</a> He describes the structure and the content of the book in his own words.</p>
<p>If you are developing RESTful web services in PHP, you will find this book will be a great reference.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/10/21/book-on-restful-php-web-services/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>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>
	</channel>
</rss>

