<?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 One Is Perfect &#187; REST</title>
	<atom:link href="http://watchitlater.com/blog/tag/rest/feed/" rel="self" type="application/rss+xml" />
	<link>http://watchitlater.com/blog</link>
	<description>A reluctant foray into the world of blogging.</description>
	<lastBuildDate>Sun, 13 Jun 2010 03:35:03 +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>Post-Redirect-Get in Rails</title>
		<link>http://watchitlater.com/blog/2010/03/post-redirect-get-in-rails/</link>
		<comments>http://watchitlater.com/blog/2010/03/post-redirect-get-in-rails/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 13:06:28 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[My Code]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[haml]]></category>
		<category><![CDATA[post-redirect-get]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[resource]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[sass]]></category>

		<guid isPermaLink="false">http://watchitlater.com/blog/?p=182</guid>
		<description><![CDATA[For a while now I&#8217;ve been flying the flag for using a post-redirect-get design pattern when writing web applications. In my opinion the current crop of web frameworks still make it very easy to do the &#8220;bad&#8221; thing since to do PRG properly you need to think what kind of an interaction you want with [...]]]></description>
			<content:encoded><![CDATA[<p>For a while now I&#8217;ve been flying the flag for using a <a href="http://en.wikipedia.org/wiki/Post/Redirect/Get">post-redirect-get</a> design pattern when writing web applications. In my opinion the current crop of web frameworks still make it very easy to do the &#8220;bad&#8221; thing since to do PRG properly you need to think what kind of an interaction you want with users and not cop out saying its technically very difficult in &lt;insert framework here&gt;. If you resort to ActiveX controls, popups without navigation bars and/or weird javascript hacks to stop users from clicking refresh or back buttons then perhaps you should have written a better web application.</p>
<p>Whenever I play with Rails, or for that matter any other web framework, I get stuck on trying to find a problem to solve (or a set of requirements). Fortunately the <a href="http://pragprog.com/titles/rails3/agile-web-development-with-rails-third-edition">Agile Development with Rails</a> book from the Pragmatic Programmers has a nice little bookstore application that I can develop iteratively. I&#8217;ve put my latest adaptation of their depot application to use post-redirect-get (even works with ActiveResource scaffolds), UUIDs as ActiveRecord primary keys, HAML, SASS and RSpec on <a href="http://github.com/tomcz/pragprog-depot-prg">GitHub</a>. Feedback is always welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://watchitlater.com/blog/2010/03/post-redirect-get-in-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PicoContainer and Jersey</title>
		<link>http://watchitlater.com/blog/2010/02/picocontainer-and-jersey/</link>
		<comments>http://watchitlater.com/blog/2010/02/picocontainer-and-jersey/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 05:40:48 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[My Code]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[ioc]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[jax-rs]]></category>
		<category><![CDATA[jersey]]></category>
		<category><![CDATA[jersey-pico]]></category>
		<category><![CDATA[PicoContainer]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://watchitlater.com/blog/?p=154</guid>
		<description><![CDATA[The Jersey JAX-RS project provides bindings for springframework and google-guice. However I wanted to see what it would take to use PicoContainer as an IoC container within Jersey.
Verdict: not much at all. Nicely extensible.
To see what I mean please take a look at my jersey-pico project on GitHub. I can now create JAX-RS services in [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="https://jersey.dev.java.net">Jersey JAX-RS</a> project provides bindings for springframework and google-guice. However I wanted to see what it would take to use <a href="http://www.picocontainer.org">PicoContainer</a> as an IoC container within Jersey.</p>
<p>Verdict: not much at all. Nicely extensible.</p>
<p>To see what I mean please take a look at my <a href="http://github.com/tomcz/jersey-pico">jersey-pico</a> project on GitHub. I can now create JAX-RS services in Java or Groovy with a very simple IoC container.</p>
]]></content:encoded>
			<wfw:commentRss>http://watchitlater.com/blog/2010/02/picocontainer-and-jersey/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django RESTful resources</title>
		<link>http://watchitlater.com/blog/2010/02/django-restful-resources/</link>
		<comments>http://watchitlater.com/blog/2010/02/django-restful-resources/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 13:34:25 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[My Code]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[resource]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://watchitlater.com/blog/?p=140</guid>
		<description><![CDATA[Last year I blogged about a neat trick in Django to have multiple views per HTTP verb. Since then I&#8217;ve been playing with RESTful applications and decided to see if there was a nicer way to expose &#8220;resources&#8221; in Django. The following is what I&#8217;ve come up with so far.
Listing: router.py

from django.http import Http404, HttpResponseNotAllowed

def [...]]]></description>
			<content:encoded><![CDATA[<p>Last year I blogged about a neat trick in Django to have <a href="/blog/2009/06/django-and-multiple-methods-per-url-pattern/">multiple views per HTTP verb</a>. Since then I&#8217;ve been playing with RESTful applications and decided to see if there was a nicer way to expose &#8220;resources&#8221; in Django. The following is what I&#8217;ve come up with so far.</p>
<p><strong>Listing: router.py</strong></p>
<pre name="code" class="py:nogutter">
from django.http import Http404, HttpResponseNotAllowed

def get_handler_method(request_handler, http_method):
    try:
        handler_method = getattr(request_handler, http_method.lower())
        if callable(handler_method):
            return handler_method
    except AttributeError:
        pass

class Resource:

    http_methods = [&#x27;GET&#x27;, &#x27;POST&#x27;, &#x27;HEAD&#x27;, &#x27;PUT&#x27;, &#x27;DELETE&#x27;, &#x27;OPTIONS&#x27;, &#x27;TRACE&#x27;]

    @classmethod
    def dispatch(cls, request, *args, **kwargs):
        request_handler = cls()

        if request.method in cls.http_methods:
            handler_method = get_handler_method(request_handler, request.method)
            if handler_method:
                return handler_method(request, *args, **kwargs)

        methods = [method for method in cls.http_methods if get_handler_method(request_handler, method)]
        if len(methods) &gt; 0:
            return HttpResponseNotAllowed(methods)
        else:
            raise Http404
</pre>
<p><strong>Listing: views.py</strong></p>
<pre name="code" class="py:nogutter">
from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from router import Resource
from models import Document
from django import forms
import identity

class DocumentForm(forms.Form):
    one = forms.CharField()
    two = forms.CharField()
    date = forms.CharField()

def index(request):
    document_links = []
    for document in Document.objects.all():
        url = reverse(&#x27;document&#x27;, args=[document.id])
        document_links.append({ &#x27;identity&#x27;: document.id, &#x27;url&#x27;: url })

    new_form_url = reverse(&#x27;document&#x27;, args=[identity.NEW])
    model = { &#x27;document_links&#x27;: document_links, &#x27;new_form_url&#x27;: new_form_url }
    return render_to_response(&#x27;index.html&#x27;, model)

def success(request, document_id):
    document = get_object_or_404(Document, pk=document_id)
    form = DocumentForm(document.get_values())
    form.is_valid()

    model = { &#x27;form&#x27;: form.cleaned_data, &#x27;index_url&#x27;: reverse(&#x27;index&#x27;) }
    return render_to_response(&#x27;success.html&#x27;, model)

class DocumentView(Resource):

    def get(self, request, document_id):
        if identity.is_new(document_id):
            form = DocumentForm()
        else:
            document = get_object_or_404(Document, pk=document_id)
            form = DocumentForm(document.get_values())

        model = { &#x27;form&#x27;: form, &#x27;index_url&#x27;: reverse(&#x27;index&#x27;) }
        return render_to_response(&#x27;form.html&#x27;, model)

    def post(self, request, document_id):
        if identity.is_new(document_id):
            document = Document()
        else:
            document = get_object_or_404(Document, pk=document_id)

        document.set_values(request.POST)
        document.save()

        form = DocumentForm(document.get_values())
        if form.is_valid():
            url = reverse(&#x27;success&#x27;, args=[document.id])
        else:
            url = reverse(&#x27;document&#x27;, args=[document.id])

        return HttpResponseRedirect(url)
</pre>
<p><strong>Listing: urls.py</strong></p>
<pre name="code" class="py:nogutter">
from django.conf.urls.defaults import *
from django.conf import settings
import os, views

urlpatterns = patterns(&#x27;&#x27;,
    url(r&#x27;^document/(?P&lt;document_id&gt;[A-Za-z0-9\-]+)/$&#x27;, views.DocumentView.dispatch, name=&#x27;document&#x27;),
    url(r&#x27;^success/(?P&lt;document_id&gt;[A-Za-z0-9\-]+)/$&#x27;, views.success, name=&#x27;success&#x27;),
    url(r&#x27;^$&#x27;, views.index, name=&#x27;index&#x27;),
)

if settings.DEBUG:
    urlpatterns += patterns(&#x27;&#x27;,
        (r&#x27;^static/(?P&lt;path&gt;.*)$&#x27;, &#x27;django.views.static.serve&#x27;,
            {&#x27;document_root&#x27;: os.path.join(os.path.dirname(__file__), &#x27;static&#x27;)}),
    )
</pre>
<p>It does add a little bit more magic to the views (since you don&#8217;t actually see the dispatch method at all) but it benefits from simpler mapping in urls.py, as well as an easier way to figure out what instance method on a Resource subclass gets called for each HTTP verb. Never felt that comfortable with popping-off of kwargs in <a href="/blog/2009/06/django-and-multiple-methods-per-url-pattern/">last year&#8217;s post</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://watchitlater.com/blog/2010/02/django-restful-resources/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
