<?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>No Rest For The Weekend &#187; html</title>
	<atom:link href="http://www.norestfortheweekend.com/category/html/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.norestfortheweekend.com</link>
	<description>Time is an illusion. Weekends doubly so.</description>
	<lastBuildDate>Mon, 22 Mar 2010 09:48:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PayPal, for shame</title>
		<link>http://www.norestfortheweekend.com/2009/11/28/paypal-for-shame/</link>
		<comments>http://www.norestfortheweekend.com/2009/11/28/paypal-for-shame/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 11:12:14 +0000</pubDate>
		<dc:creator>markstickley</dc:creator>
				<category><![CDATA[html]]></category>
		<category><![CDATA[rants]]></category>

		<guid isPermaLink="false">http://www.norestfortheweekend.com/?p=101</guid>
		<description><![CDATA[PayPal are huge. And so are their HTML errors. This post picks apart some horrible HTML from PayPal that they encourage people to paste into their own sites, and provides a healthy alternative.]]></description>
			<content:encoded><![CDATA[<img src="http://www.norestfortheweekend.com/wp-content/uploads/2009/11/shameless.jpg" alt="Screengrab of the PayPal homepage header, the word PayPal replaced with the word ShameLess" title="ShameLess" width="628" height="150" class="size-full wp-image-100" />
<p><a href="http://www.paypal.com">PayPal</a> is, as I&#8217;m sure you know, a long-standing staple of online payment technologies. They are now merged with eBay and you pretty much can&#8217;t use eBay without a PayPal account which works nicely for eBay as they are now reaping the benefit of not just the eBay selling fees but also the PayPal fees.</p>
<p>But this is not a post to lament how much money eBay/PayPal are raking in from punters.</p>
<h4>Nice and easy</h4>
<p>As well as a payment service for eBay, PayPal also offer shopping basket and checkout services for small online merchants who don&#8217;t want to buy and maintain e-commerce products. It works nicely and provided you don&#8217;t mind PayPal taking their cut it provides a really simple way of being able to take credit cards securely.</p>
<h4>Prepare yourself</h4>
<p>I was recently asked to add some shopping functions to a site using PayPal. Here is one of the nine code snippets PayPal provided me with to insert a button into my page:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;form target=&quot;paypal&quot; action=&quot;https://www.paypal.com/cgi-bin/webscr&quot; method=&quot;post&quot;&gt;
&lt;input type=&quot;hidden&quot; name=&quot;cmd&quot; value=&quot;_s-xclick&quot;&gt;
&lt;input type=&quot;hidden&quot; name=&quot;hosted_button_id&quot; value=&quot;xxxxxxx&quot;&gt;
&lt;table&gt;
&lt;tr&gt;&lt;td&gt;&lt;input type=&quot;hidden&quot; name=&quot;on0&quot; value=&quot;Sizes&quot;&gt;Sizes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;select name=&quot;os0&quot;&gt;
	&lt;option value=&quot;XXSmall&quot;&gt;XXSmall £20.00&lt;/option&gt;
	&lt;option value=&quot;XSmall&quot;&gt;XSmall £20.00&lt;/option&gt;
	&lt;option value=&quot;Small&quot;&gt;Small £20.00&lt;/option&gt;
	&lt;option value=&quot;Medium&quot;&gt;Medium £20.00&lt;/option&gt;
	&lt;option value=&quot;Large&quot;&gt;Large £20.00&lt;/option&gt;
	&lt;option value=&quot;XLarge&quot;&gt;XLarge £20.00&lt;/option&gt;
&lt;/select&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
&lt;input type=&quot;hidden&quot; name=&quot;currency_code&quot; value=&quot;GBP&quot;&gt;
&lt;input type=&quot;image&quot; src=&quot;https://www.paypal.com/en_GB/i/btn/btn_cart_LG.gif&quot; border=&quot;0&quot; name=&quot;submit&quot; alt=&quot;PayPal - The safer, easier way to pay online.&quot;&gt;
&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;https://www.paypal.com/en_GB/i/scr/pixel.gif&quot; width=&quot;1&quot; height=&quot;1&quot;&gt;
&lt;/form&gt;</pre></div></div>

<p>Oh PayPal, how do you sadden me? Let me count the ways&#8230;</p>
<h4>Spot the nastiness</h4>
<p>Well being generous, there are 7 horrible things about that above code snippet. If I count each problem every time it appears I reach a grand total of 12. Bleugh.</p>
<p>Let me run through exactly what I take issue with, because I really don&#8217;t think I&#8217;m being unreasonable.</p>
<h5>Inputs</h5>
<p>There are a lot of hidden <code>input</code>s. No, I understand &#8211; they need to be there to make it work. That makes sense. What doesn&#8217;t make sense is that they don&#8217;t bother to close off the <code>input</code>s, XHTML style.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;input type=&quot;hidden&quot; name=&quot;name&quot; value=&quot;value&quot; /&gt;</pre></div></div>

<p>Simple.</p>
<h5>Tables</h5>
<p>Really? Tables? But look at it. What does it actually do? Absolutely nothing, apart from put the text and the select side by side, which is a choice for the designer to make. No <code>tbody</code>, no <code>th</code>&#8217;s, and so there&#8217;s no chance in hell of any <code>scope=</code>&#8217;s.</p>
<p>Pointless.</p>
<h5>Select with no id and no label</h5>
<p>I don&#8217;t think I need to say a lot about this &#8211; the title says it all. They&#8217;ve put the text that should be in the label in plain text instead. They could have used the table (if they insisted on having one) to help with this by putting the label text in a th, but they didn&#8217;t even do that.</p>
<h5>Input type: image</h5>
<p>Again, no problem in using an input of type image. But wait&#8230; they didn&#8217;t specify the width and height! If they are going to go for a consistent look, as they appear to be doing with their tables mentioned earlier, then this is essential. Otherwise, rogue styles applied to all <code>input</code>s will seriously mess up the look of the button.</p>
<h5>Alt text</h5>
<p>Possibly the worst offender of all.</p>
<p>Check it out, aren&#8217;t PayPal good? They added alt text and everything. Except the alt text is on the image input element &#8211;  the submit button &#8211;  and it isn&#8217;t at all descriptive. It&#8217;s basically an advert for PayPal. </p>
<p>What good is that to <abbr title="Assistive Technology">AT</abbr> users? They would have <strong>no clue</strong> as to what that control does.</p>
<h5>Spacer gif</h5>
<p>Yes, for no apparent reason there is a spacer gif at the bottom of it all. And yes, it has no XHTML closing slash.</p>
<h5>No enclosing element</h5>
<p>Oh yes, one last one. <code>input</code> elements can&#8217;t reside directly inside the <code>form</code> element. They need to be contained within any one of a variety of other elements (Eg. <code>p</code>, <code>div</code>, etc.). Sadly, there is nothing protecting our <code>input</code>s from the harsh reality of their <code>form</code> overlord.</p>
<h4>The way it <em>should</em> be</h4>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;form target=&quot;paypal&quot; action=&quot;https://www.paypal.com/cgi-bin/webscr&quot; method=&quot;post&quot;&gt;
	&lt;div&gt;
		&lt;input type=&quot;hidden&quot; name=&quot;cmd&quot; value=&quot;_s-xclick&quot; /&gt;
		&lt;input type=&quot;hidden&quot; name=&quot;hosted_button_id&quot; value=&quot;xxxxxxx&quot; /&gt;
		&lt;input type=&quot;hidden&quot; name=&quot;on0&quot; value=&quot;Sizes&quot; /&gt;
		&lt;label for=&quot;sizes-polo&quot;&gt;Sizes&lt;/label&gt;
		&lt;select name=&quot;os0&quot; id=&quot;sizes-polo&quot;&gt;
			&lt;option value=&quot;XXSmall&quot;&gt;XXSmall £20.00&lt;/option&gt;
			&lt;option value=&quot;XSmall&quot;&gt;XSmall £20.00&lt;/option&gt;
			&lt;option value=&quot;Small&quot;&gt;Small £20.00&lt;/option&gt;
			&lt;option value=&quot;Medium&quot;&gt;Medium £20.00&lt;/option&gt;
			&lt;option value=&quot;Large&quot;&gt;Large £20.00&lt;/option&gt;
			&lt;option value=&quot;XLarge&quot;&gt;XLarge £20.00&lt;/option&gt;
		&lt;/select&gt;
		&lt;input type=&quot;hidden&quot; name=&quot;currency_code&quot; value=&quot;GBP&quot; /&gt;
		&lt;div class=&quot;controls&quot;&gt;
			&lt;input class=&quot;image&quot; width=&quot;120&quot; height=&quot;26&quot; type=&quot;image&quot; src=&quot;https://www.paypal.com/en_GB/i/btn/btn_cart_LG.gif&quot; name=&quot;submit&quot; alt=&quot;Add a polo shirt in the selected size to your cart&quot; /&gt;
		&lt;/div&gt;
	&lt;/div&gt;
&lt;/form&gt;</pre></div></div>

<p>Much better. Notice that for the alt text I mentioned which item was being added and referenced the size select box in case they AT user might have missed that, or not made a selection yet.</p>
<h4>Why am I picking on PayPal?</h4>
<p>Well, I&#8217;m sure that many other large companies are equally guilty of this sort of thing. And as I come across them, if they enrage me enough I&#8217;m sure I&#8217;ll rant about them as well. But really, PayPal should know better. They event have people coming to (and sponsor) events (like <a href="http://www.barcamp.org/">BarCamp</a>) where the attendees have a low tolerance for this sort of thing.</p>
<p>Hopefully if enough people make a fuss, these things will change. Don&#8217;t tolerate it! And most of all, never blindly cut and paste markup from another site. It&#8217;ll only make you look bad.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.norestfortheweekend.com/2009/11/28/paypal-for-shame/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>On forms, submit buttons and browsers</title>
		<link>http://www.norestfortheweekend.com/2009/10/20/on-forms-submit-buttons-and-browsers/</link>
		<comments>http://www.norestfortheweekend.com/2009/10/20/on-forms-submit-buttons-and-browsers/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 09:10:52 +0000</pubDate>
		<dc:creator>markstickley</dc:creator>
				<category><![CDATA[html]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[submit]]></category>

		<guid isPermaLink="false">http://www.norestfortheweekend.com/?p=59</guid>
		<description><![CDATA[Forms are tricky beasts and no less so when they behave differently in different browsers. This post explores how different browsers react to submit buttons in different ways, and how to get around it.]]></description>
			<content:encoded><![CDATA[<p>Aah, ambiguity! What a tricky devil you are. The <a href="http://www.w3.org">W3C</a> Recommendations are normally very specific and not at all ambiguous, but when things are left open to interpretation you can be fairly sure of varying results.</p>
<h4>Bad form, old chap</h4>
<p>Have a look at this form:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;form action=&quot;wherever.html&quot; method=&quot;post&quot;&gt;
    &lt;label for=&quot;firstname&quot;&gt;First name&lt;/label&gt;
    &lt;input name=&quot;firstname&quot; id=&quot;firstname&quot; type=&quot;text&quot; /&gt;
&nbsp;
    &lt;input type=&quot;submit&quot; name=&quot;proceed&quot; value=&quot;Proceed&quot; /&gt;
&nbsp;
    &lt;input type=&quot;submit&quot; name=&quot;back&quot; value=&quot;Back&quot; /&gt;
&lt;/form&gt;</pre></div></div>

<p>What gets submitted when you hit Proceed? Well yes, <code>firstname</code> is included as is <code>proceed</code>, but is <code>back</code>? What gets submitted when you hit Back, as the second submit button in the form?</p>
<p>Well the <a href="http://www.w3.org/TR/html401/interact/forms.html#submit-format">W3C Guidelines on form submission</a> say that for forms with more than one submit button, only the submit button that was pressed should be submitted. This seems fair enough.</p>
<p><strong>But what gets submitted when you press enter from within the text field?</strong></p>
<p>The W3C has no recommendation for this! The precise wording used to qualify whether a submit button gets sent along with the other form data is:</p>
<blockquote cite="http://www.w3.org/TR/html401/interact/forms.html#submit-format"><p>If a form contains more than one submit button, only the activated submit button is successful.</p></blockquote>
<p>&#8230;where &#8216;activated&#8217; means having been clicked on to submit the form and being &#8217;successful&#8217; refers to the selection process for including form elements in the request.</p>
<h4>Pressing the right buttons (or not, as the case may be)</h4>
<p>What actually happens varies between browsers, which I suppose is no surprise really. The surprise is which browsers do what.</p>
<p>We see two behaviors here:</p>
<ul>
<li>IE (I tested 6, 7 &#038; 8) works on the basis that you only submit an <em>activated</em> form element and the only way to activate a submit button is to <em>click on it</em>. Therefore if you click on a submit button, IE will submit it&#8217;s value along with the rest of the form, but if you press <em>Enter</em> to submit it doesn&#8217;t submit the value of <em>any</em> submit buttons.</li>
<li>All other browsers (tested: Firefox, Safari, Chrome, Opera) submit a value for a submit button, <em>whether or not you click it</em>. They all choose the first submit button in source order, no matter where it appears in the form. Thank goodness that&#8217;s consistent!</li>
</ul>
<p>I guess that the other browsers think it&#8217;s fair to assume that pressing enter while entering data into a form is the same as clicking on the submit button, which in most cases it is. But what happens when you&#8217;ve got two or more submit buttons? How do you know which button the user wanted to click? How can the developer predict that, supposing they even know about this peculiarity? Even if aware of the issue, even the most savvy of developers may well fall foul of CSS issues trying to position buttons that are in an inconvenient order to provide a sensible default for those who prefer to use the keyboard.</p>
<p>Yes, this time <em>I think IE got it right</em>!</p>
<h4>How to fix the problem</h4>
<p>I think anyone that works with browsers will admit that we all dream of a world where they all have consistent and good behavior. But failing that, consistent behavior would be nice. </p>
<p>I&#8217;m not convinced that all the other browsers will change their behavior any time soon (even if they could be convinced that what they are doing isn&#8217;t the right option) as there are probably hundreds of thousands of sites out there that will break if it changes. So the best thing to do is to &#8216;fix&#8217; IE to behave the same.</p>
<p>Here&#8217;s the code:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;form action=&quot;wherever.html&quot; method=&quot;post&quot;&gt;
    &lt;label for=&quot;firstname&quot;&gt;First name&lt;/label&gt;
    &lt;input name=&quot;firstname&quot; id=&quot;firstname&quot; type=&quot;text&quot; /&gt;
&nbsp;
    &lt;input type=&quot;hidden&quot; name=&quot;submit_button&quot; value=&quot;Proceed&quot; /&gt;
    &lt;input type=&quot;submit&quot; name=&quot;submit_button&quot; value=&quot;Proceed&quot; /&gt;
&nbsp;
    &lt;input type=&quot;submit&quot; name=&quot;submit_button&quot; value=&quot;Back&quot; /&gt;
&lt;/form&gt;</pre></div></div>

<p>You&#8217;ll notice I changed a few things around! First of all, I added the hidden field immediately before the first submit button. The first button is the one which acts as the default button in FF, Safari <em>et al.</em> and so we are making it do the same in IE. By adding a hidden field with the same name and value as the first button <strong>immediately before</strong> the button itself, it effectively acts as a default. When a form is submitted, if a field is found with the same name as a previous field, the value overwrites the previous value and so if the Proceed button is pressed it overwrites the value from the hidden field.</p>
<p>In IE if the user presses Enter to submit the form, neither button is pressed and the hidden field gets submitted. But as it has the same name and value as the Proceed button, it&#8217;s as if the Proceed button was pressed. In the other browsers the value of the Proceed button overwrites the value of the hidden field and so it&#8217;s like it&#8217;s not even there.</p>
<p>That&#8217;s all fine but if the Back button is clicked the hidden field will be submitted as well giving an impossible value for both the submit buttons in the same request! That&#8217;s why I&#8217;ve also changed the name of the Back button to be the same as the name of the Proceed button &#8211; that way there will always be a value submitted for <code>submit_button</code>: either &#8220;Back&#8221; or the default &#8220;Proceed&#8221;.</p>
<p><em>Notice I didn&#8217;t call any of the fields &#8220;<code>submit</code>&#8220;. That was intentional, and it&#8217;s because if we ever want to submit the form via Javascript having a field named <code>submit</code> would make that impossible.</em></p>
<h4>But is it really a problem?</h4>
<p>That solution is a bit clunky to be honest. Having the extra field is a bit of a hack and the fact that you have to call the hidden field and both submit buttons by the same name make it a little restrictive, especially when it doesn&#8217;t even need to be a problem.</p>
<p>Armed with the knowledge in this article we know that we can&#8217;t rely on the values of the submit buttons to be broadcast. If we don&#8217;t know which button has been clicked, we simply choose a default action and perform that unless we detect the alternative action. In PHP and for the first form it would go something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_METHOD'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'POST'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// if a form was submitted</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'back'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// if the back button was clicked</span>
		<span style="color: #666666; font-style: italic;">// Perform back action </span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Perform default action</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>So long as you don&#8217;t assume the button to be clicked in order to perform the default action, life will be good!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.norestfortheweekend.com/2009/10/20/on-forms-submit-buttons-and-browsers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>REST For The Weekend</title>
		<link>http://www.norestfortheweekend.com/2009/08/25/rest-for-the-weekend/</link>
		<comments>http://www.norestfortheweekend.com/2009/08/25/rest-for-the-weekend/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 15:05:20 +0000</pubDate>
		<dc:creator>markstickley</dc:creator>
				<category><![CDATA[html]]></category>
		<category><![CDATA[architectures]]></category>
		<category><![CDATA[crud]]></category>
		<category><![CDATA[mime]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[restful]]></category>

		<guid isPermaLink="false">http://www.norestfortheweekend.com/?p=24</guid>
		<description><![CDATA[What is REST? People talk about it like it's a good thing. It is, but not in all cases. This post teaches you about the basics of REST so you can make the right decision.]]></description>
			<content:encoded><![CDATA[<p>Oh well, the weekend&#8217;s over again. What did you do? I got an impressive sunburn, bought some delicious fruit and veg at the market and looked into RESTful architectures, among other things. Although I would love to tell you about my culinary adventures, what I&#8217;m going to write about now is REST. It should be noted that in this case REST is not sitting in front of the TV and has nothing to do with the title of this blog, despite what you may think!</p>
<h4>What REST is not</h4>
<p>There seems to be some confusion over exactly what a RESTful architecture is. Some people think it is pretty URLs:</p>
<pre>

http://www.mysite.com/portfolio/design/someclient
</pre>
<p>as opposed to:</p>
<pre>
http://www.mysite.com/index.php?section=portfolio »
    &#038;subsection=design&#038;client=someclient
</pre>
<p>This is not RESTful.</p>
<p>Some people think REST is a bunch of actions triggered by visiting URLs:</p>
<pre>

http://www.mysite.com/contact/email/send
</pre>
<p>This isn&#8217;t RESTful either.</p>
<h4>Being resourceful</h4>
<p>REST stands for <strong>RE</strong>presentational <strong>S</strong>tate <strong>T</strong>ransfer and it&#8217;s all about resources. That is to say, data presented in a formatted way and made available at specific, addressable points of entry. Most of the time when people talk about a REST interface they will be talking about the web and URLs, but REST is not limited to this technology. So long as each resource on a system can be identified uniquely, manipulated, each request for resources includes enough information that the client knows how to process it and has the ability to contain references to other resources then it can be called RESTful.</p>
<p>A RESTful system is a stateless system; each resource request in a RESTful system should be completely independent of any other. It should not rely on cookies, session variables or any other state maintaining solutions. This is because a REST request is intended to be performed on the current state of the specified resource and the resource should be able to be encapsulated in a single response.</p>
<h4>Strict instructions</h4>
<p>It might have slipped under the radar but a couple of paragraphs above I mentioned that a REST response should include information for the client on how to process the data. In the case of a web service (and it should be assumed from here on out I&#8217;ll be talking about web services) the <a href="http://en.wikipedia.org/wiki/MIME_type">MIME type</a> should be sufficient. For example, if you are serving your response up as JSON you&#8217;d want to use the <strong>MIME type</strong>: <code>application/json</code>. The <strong>MIME type</strong> is contained within the header of the response.</p>
<p>In a similar manner, the client needs to tell the server what it wants to do with the specific resource. We can do this by specifying the correct <a href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods">HTTP Method</a> as part of the request.</p>
<h4>Method in madness</h4>
<p>So the HTTP methods most people are used to are: <code>GET</code> (the default method, what you get when you hit enter after typing a URL) and <code>POST</code> (the method used for submitting most forms). The others we are interested in are <code>PUT</code> and <code>DELETE</code>. Using these four methods we can instruct a RESTful interface to perform the basic <abbr title="Create, Read, Update, Delete">CRUD</abbr> operations:</p>
<ul>
<li><strong>C</strong>reate = <code>POST</code></li>
<li><strong>R</strong>ead = <code>GET</code></li>
<li><strong>U</strong>pdate = <code>PUT</code></li>
<li><strong>D</strong>elete = <code>DELETE</code> (rather unsurprisingly)</li>
</ul>
<p>Using these methods you can manipulate a resource in any way you like from that single addressable entry point. If you have the URL for the resource, in a RESTful architecture you know you won&#8217;t have to append strings to the URL to make it do things (Eg <code>?action=delete</code>) &#8211; you just change the method used to request the resource in the request header.</p>
<p>Obviously if your system is externally accessible you will probably want to limit access to the &#8216;unsafe&#8217; <code>POST</code>, <code>PUT</code> and <code>DELETE</code> methods.</p>
<h4>Not for everyone</h4>
<p>So as you can tell, REST isn&#8217;t something you should strive to include just for the sake of it. I can&#8217;t stress this enough: <em>there&#8217;s no point in shoehorning REST into a site or project when it is not really needed</em>. The main use for it it most likely to be for Web Service APIs and anything that is highly resource driven. Think of it as a series of defined views on a database or other resource and you can&#8217;t go too far wrong.</p>
<p>I am currently working on a web based file system for storing assets as part of a CMS. It has an API so that you can add, edit, read and delete assets from external locations, providing that you present the right credentials. This almost seems like the perfect application for REST as each entry &#8211; be it a file or a folder &#8211; needs to have the basic CRUD operations performed on it. The whole URL structure is basically the directory tree and every point in that tree is addressable and will accept all the different methods.</p>
<h4>Testing, testing</h4>
<p>This is all very well, but how do you go about testing these crazy HTTP methods, practically? You can&#8217;t have a page full of links to click because a link is a <code>GET</code> request. There&#8217;s no way of changing that. </p>
<p>Forms offer a little flexibility &#8211; you can specify the method you want to use with the method attribute. Unfortunately this is restricted to <code>GET</code> and <code>POST</code>. If you try anything other than that it will default to <code>GET</code>.</p>
<p>To test these request methods, you have to hand craft an HTTP request. You can do this in the server-side scripting language of your choice (Eg PHP, Ruby, Python etc) <em>OR</em> you can download one of the handy Firefox extensions that kindly developers have made available for nothing for this very purpose! My personal favourite is <a href="https://addons.mozilla.org/en-US/firefox/addon/9780">RESTClient</a> by <a href="http://www.porphyry.org/">Chao ZHOU</a> but there are plenty of others for you to choose from. Here are a few:</p>
<ul>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/2691">Poster</a> by <a href="http://www.milowski.com/">Alex Milowski</a></li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/5946">RESTTest</a> by <a href="http://www.xucia.com/">kriszyp</a></li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/967">Modify Headers</a> by <a href="http://www.garethhunt.com/">Gareth Hunt</a></li>
</ul>
<h4>Using RESTClient</h4>
<p>It&#8217;s pretty simple really. The basic interface looks like this:</p>
<div id="attachment_25" class="wp-caption aligncenter" style="width: 628px"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2009/08/restclient.gif" alt="The RESTClient interface displays fields for method, url, header and request body along with an area in which to display the response. At the top are controls to open &amp; save your request amongst other things." title="RESTClient screenshot" width="618" height="603" class="size-full wp-image-25" /><p class="wp-caption-text">The RESTClient interface displays fields for method, url, header and request body along with an area in which to display the response. At the top are controls to open &#038; save your request amongst other things.</p></div>
<ol>
<li>Choose your request method</li>
<li>Type the resource location</li>
<li>Add any request headers you need (this is like items from form fields)</li>
<li>Type the request body you want to transmit (this can be left blank most of the time)</li>
<li>Hit send</li>
</ol>
<p>What you will get back is the response as the server sends it. You can inspect the header and the body to make sure it&#8217;s coming back as you&#8217;d expect and so your application that will consume the response won&#8217;t get any nasty surprises!</p>
<p>Hopefully you are interested in RESTful architectures now, and are feeling inspired to go off and write one of your own!</p>
<p class="furtherreading">For more information on this topic, check out the <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">Wikipedia article on REST</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.norestfortheweekend.com/2009/08/25/rest-for-the-weekend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->