<?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>Custom Software Development Company, Rich Media Application Development, Business Application Development, Web Application Development &#187; RESTful development</title>
	<atom:link href="http://www.blog.rightwaysolution.com/tag/restful-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.blog.rightwaysolution.com</link>
	<description></description>
	<lastBuildDate>Mon, 30 Jan 2012 13:04:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>What is RESTful development and how easy to develop a RESTful web application using cakephp framework?</title>
		<link>http://www.blog.rightwaysolution.com/develop-a-restful-web-application-using-cakephp-framework/</link>
		<comments>http://www.blog.rightwaysolution.com/develop-a-restful-web-application-using-cakephp-framework/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 07:40:24 +0000</pubDate>
		<dc:creator>Rakesh Jain</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[RWS News]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful API]]></category>
		<category><![CDATA[RESTful API Development]]></category>
		<category><![CDATA[RESTful Architecture]]></category>
		<category><![CDATA[RESTful development]]></category>
		<category><![CDATA[RESTFul web development]]></category>
		<category><![CDATA[Web services]]></category>

		<guid isPermaLink="false">http://www.blog.rightwaysolution.com/?p=314</guid>
		<description><![CDATA[Nowadays RESTful architecture based API (web services)  development is accepted across the Web as a simpler alternative to SOAP &#8211; and  Web Services Description Language (WSDL)-based Web services. Key evidence of  this shift is the adoption of REST by web 2.0 service providers, including  Yahoo, Google, and Facebook, who have shifted [...]]]></description>
			<content:encoded><![CDATA[<p>Nowadays RESTful architecture based API (web services)  development is accepted across the Web as a simpler alternative to SOAP &#8211; and  Web Services Description Language (WSDL)-based Web services. Key evidence of  this shift is the adoption of REST by web 2.0 service providers, including  Yahoo, Google, and Facebook, who have shifted their SOAP and WSDL-based web  services to RESTFul API. RESTful development has become the standard way of  creating a web application. So, let&#8217;s explore the question of what is RESTful  development and how easy to develop a RESTful web application using cakephp  framework?</p>
<h2>What  is RESTful Development?</h2>
<p><strong>REpresentational State Transfer (REST)</strong> is a stateless  client-server architecture in which the resources are identified by their URLs  and are manipulated through their representations, this basically means that  each unique URL is a representation of some object (resource).  Within the REST architecture, requests from  the Web service clients or browser use standard HTTP methods to manipulate the  application&#8217;s resources. As far as REST is concerned GET, POST, PUT, and DELETE  HTML methods are used to manipulate resources. However, the HTTP protocol defines  eight methods, GET, POST, PUT, DELETE, HEAD, TRACE, OPTIONS, and CONNECT</p>
<p>In traditional MVC based framework a URL would specify a  resource and its action. For example:</p>
<p><em>http://www.mydomain.com/articles/show/5 </em></p>
<p>This URL will tell the framework to display the details of 5th  number article by using show action/method of article controller. But in REST  architecture URL don’t specify the action, URL only specify the resource and  the action of resource is determined by HTTP method used with which the request  is submitted. For example, in RESTful architecture the above URL would be:</p>
<p><em>http://www.mydomain.com/articles/5 </em></p>
<p>This URL would be submitted using the HTTP GET method, in  RESTful based architecture the framework will route it to show method of  article resource(controller) by determining that request is submitted by using  GET method.</p>
<p>The table below shows how various actions  performed on a resource are mapped to URLs and HTTP methods.</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="125" valign="top"><strong>HTTP Method</strong></td>
<td width="338" valign="top"><strong>URL</strong></td>
<td width="213" valign="top"><strong>Action / Method </strong></td>
</tr>
<tr>
<td width="125" valign="top">GET</td>
<td width="338" valign="top"><em>http://www.mydomain.com/articles/5</em></td>
<td width="213" valign="top">show</td>
</tr>
<tr>
<td width="125" valign="top">DELETE</td>
<td width="338" valign="top"><em>http://www.mydomain.com/articles/5</em></td>
<td width="213" valign="top">delete</td>
</tr>
<tr>
<td width="125" valign="top">PUT</td>
<td width="338" valign="top"><em>http://www.mydomain.com/articles/5</em></td>
<td width="213" valign="top">update</td>
</tr>
<tr>
<td width="125" valign="top">POST</td>
<td width="338" valign="top"><em>http://www.mydomain.com/articles/</em></td>
<td width="213" valign="top">create</td>
</tr>
</tbody>
</table>
<p><strong>Note </strong>- The URL for performing show, delete, and  update on a resource is same and are routed to the correct action of article  controller based on the HTTP method that is used to submit them.</p>
<h2>What are the advantages of RESTful development  or RESTful architecture based development?</h2>
<p>It is very hard to describe every benefit of a RESTful  architecture based development but here I am going to describe few one</p>
<p><strong>Well Defined  architecture Design</strong> &#8211; RESTful architecture define a standard way of  implementing controllers and access to models in a web application. you would  apply this pattern throughout your web application&#8217;s architecture. Every  controller would consist of the same standard set of methods show, delete,  update, and create. The application framework will route to the correct method  based on looking at both the URL and the HTTP method used for incoming  requests. You have great consistency in your web applications. All of your  controllers are implemented in the same style and contain the same set of  methods.</p>
<p><strong>REST is a web service  Architecture</strong> &#8211; The REST architecture provides an excellent platform for  providing API interface as web service, as in RESTful architecture every  resource can be manipulated by using HTTP methods and a resource can have  multiple representations. For example, considering the book example again, you  could easily imagine a web service API that used URLs identical to that which a  browser uses to get HTML content.</p>
<p><strong>Multiple  representations for a resource </strong>-  When you request a page using a RESTful architecture, the page that is returned  can be considered a representation of the resource that you are requesting.  However, an HTML page is just one possible representation of any given  resource. Other representations might include an XML document, a text document,  or a block of JSON encoded JavaScript. Using the RESTful architecture, you  would request a different representation of a resource using the same method,  but by passing a different piece of metadata to the server indicating the  representation that you would like to have returned. For example the following  two requests would both be routed to the same controller and action method:</p>
<p><em>http://www.mydomain.com/article/5</em></p>
<p><em>http://www.mydomain.com/article/5.xml</em></p>
<p>The first request would return an HTML representation of the article resource.  The second request would return an XML representation of the article resource.  This is another advantage of a RESTful architecture. The same controllers and  actions can be used to deliver a variety of response (HTML, RSS, XML, etc).  This makes implementing web services in a RESTful architecture extremely easy,  and again maintains a consistent design style.</p>
<h2>How easy to develop a RESTful architecture based  web application using cakephp framework?</h2>
<p>The power of CakePHP has a lot to do with conventions. The  framework enforce certain conventions and standards that users <em>must</em> follow. You name your database  tables, file names, etc; a particular way and boom, models, views and  controllers are automatically created and ready for use. This is the beauty of  the MVC structure. Your URLs also follow thing structure:  <em>www.mydomain.com/controller/action/params </em>(in our article example it would be <em>www.mydomain.com/articles/view/1). </em></p>
<p>According to the introduction of a controller given in  cookbook of cakephp, A controller is used to manage the logic for a part of  your application. Most commonly, controllers are used to manage the logic for a  single model. For example, if you were building a site for an online bakery,  you might have a RecipesController and a IngredientsController managing your recipes  and their ingredients. Controllers can include any number of methods which are  usually referred to as <em>actions</em>. An  action is a single method of a controller. CakePHP’s inbuilt dispatcher calls  actions when an incoming request matches a URL to a controller’s action</p>
<p>You can easily add REST functionality to your application  with only a few changes, below are all changes which you need to make to get  REST benefits:</p>
<ol>
<li>Open <em>app/config/routes.php</em> file and add <em>Router::mapResources(‘article’);</em> line at the end of the file (here article is a resource and a  controller of the application), this line will map GET, POST, PUT, DELETE HTML  methods with index, view(show), add(creation), edit(update), delete  methods/actions of article resource (controller). This line has to be repeated  for every resource. So this single line has done the half job for making an  RESTful architecture based web application development. Now only thing which  remains for complete RESTful development is multiple representations of a  resource. This is also very smartly handled in cakephp framework and described  below in 2rd, 3rd and 4th points.</li>
<li>Add <em>Router::parseExtensions();</em> line after <em>Router::mapResources(‘article’); </em></li>
<li>Include<em> RequestHandler </em>component in article  controller [var $components = array('RequestHandler');]</li>
<li>At last for every alternative type  of representations of a resource you need add a directory under <em>views/articles</em> and <em>views/layouts,</em> the name of the directory would be extension such as  txt, pdf, doc etc…(note – that in case of xml you don’t have to create  directory under <em>views/layouts</em> as this is  already provided by cakephp standard installation).</li>
</ol>
<p>Once you follow above 4 points as described, you will have  RESTful architecture ready for your application. So it is quite easy to develop  a REST based web application using cakephp framework. I am very thankful to  cakephp community &amp; development team who has developed and provided such a  nice framework which makes our life quite easy for developing RESTful API or  doing RESTful development (RESTFul api development).</p>
<p>Hope this posting helped you, if you have any suggestion,  question feel free to contact me at <a href="mailto:rakesh@rightwaysolution.com">rakesh@rightwaysolution.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.rightwaysolution.com/develop-a-restful-web-application-using-cakephp-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

