Programming - - By Harry Fuecks

Who GETs REST?

Prompted by looking at Catalyst and Handel in particular, has me thinking about that whole REST thing again.

Seems to me that very few people get the point (and I’m not claiming I do). There’s been alot of smart debate, some even down to earth, but what does REST really mean? What are practical consequences web developers can use? How do we eliminate grey areas? Is this REST?

What I’m pretty sure of is what Roy was describing is, at heart, a very simple set of ideas, based on a simple protocol that provides everything you need. But in the endless debate vs. SOAP the point seems to have been lost.

One particular quote from the Wikipedia interpretation

With REST […] the emphasis is on the diversity of resources, or nouns

Turning that on it’s head, how about this as a bold statement that we can actually use:

Never put verbs in URLs

To that extent made this change so that this URL – http://www.example.org/users/search?surname=Michaels becomes this: http://www.example.org/users?surname=Michaels

Will kick off with two exceptions (but I think the only exceptions) – domain names or where the verb is actually part of the name (such as a title in a “search engine friendly” URL) like this

Think the consequences which fall out of that rule could make frameworks much easier to use if APIs get designed around it – a middle ground between this and frameworks like Catalyst and Rails which I think have inverted the problem into this form.

In Catalyst terms that boils down to controllers like;


package MyApp::Controller::Cart::Item;

use strict;
use base 'Catalyst::Base';

sub new : Regex('^(d+)$') {
     my $class = shift;
     my $self = Catalyst::Base->new();
     bless($self, $class);
     return $self;
}

sub GET {
    my ( $self, $c ) = @_;
    # Do HTTP GET stuff here
}

sub POST {
    my ( $self, $c ) = @_;
    # Do HTTP POST stuff here
}

sub DELETE {
    my ( $self, $c ) = @_;
    # perhaps...
}

Will leave it there. Feel free to POST flames or whatever

Sponsors