[Catalyst] Re: Catalyst::Action::REST

John Napiorkowski jjn1056 at yahoo.com
Mon Nov 20 15:24:12 GMT 2006


--- "A. Pagaltzis" <pagaltzis at gmx.de> wrote:

> * Matt S Trout <dbix-class at trout.me.uk> [2006-11-20
> 15:25]:
> > Feel free to propose a variant on the syntax
> marcus proposed
> > that  will allow the implementation of equivalent
> functionality
> > without the  addition of multimethods to the perl
> core.
> 
> Oh! Now I feel silly.
> 
> Eh.
> 
> OK, to lay out my own thinking a little, when I was
> doing my
> silly PATHINFO-based hack-up of
> CGI::Prototype::Hidden, the plan
> eventually became to have one class per handler,
> with methods
> named after, err, methods, eg.:
> 
>     sub GET  { ... }
>     sub POST { ... }
>     sub HEAD { ... }
> 
> I still think that’s cleanest approach.
> 
> Catalyst as it stands somewhat encourages a
> confusion between
> nouns (URIs) and verbs (methods), with URIs like
> `/entry/1234/comments/add`, where the
> `/entry/1234/comments` part
> identifies a resource, but the `/add` bit at the end
> is really an
> verb. That should simply be a POST to
> `/entry/1234/comments`. And
> most of the time, if the design is RESTful from the
> start, you
> can implement a web app as pure CRUD using the HTTP
> methods; eg.
> the methods in a controller should simply correspond
> 1:1 to HTTP
> verbs. That was as far as I had gotten my own
> thoughts.

One this that I think works really well in catalyst is
how easy it it so divide your private names from the
public urls.  So you can do:

Package myapp::Controller::foo

__PACKAGE__->_action_class('Custom::Rest');

sub foos :Chained('/') PathPart('') CaptureArgs(0) {}

sub create :Chained('foos') PathPart('') Args(0)
Method(POST) Method(PUT) Method(POST) {}

sub foo :Chained('foos) PathPart('') CaptureArgs(1) {}

sub update :Chained('foo') PathPart('') Args(0)
Method(POST) {}

sub delete :Chained('foo') PathPart('delete') Args(0)
Method(POST) METHOD(DELETE) Method(GET) {}

In the example above I loaded a custom action class to
handle the Method Attributes.  I end up having to
support a verby delete URL because most user clients
can't send an HTTP DELETE from a form in HTML, but
that's just coping with reality.

Maybe it get's a little verbose, but then I can have
sane names for my templates, like 'foos/create,
foos/delete, foos/update, etc'.  Also it creates sane
URL with
$c->uri_for($c->controller('foos')->action_for('create'));

Doing it this way gives you the noun oriented URI you
spoke of, but keeps the actions as verbs inside your
code.

However I do find that with heavy use of action
classes my controllers start to look rather empty :)

Cheers, John

> 
> Of course, there are going to be some cases where
> that isn’t
> quite enough; for these, you could have the option
> of adding
> methods that work as if they were custom invented
> HTTP methods.
> The framework could permit tunneling unsupported
> methods inside
> POST requests, which it would automatically unravel
> before
> dispatching. The Rails guys were doing something
> along these
> lines; I have to take another look sometime.
> 
> What I don’t like about the current proposals in
> Catalyst-land
> is that they make the RESTful approach a wordy
> non-default
> option. It takes quite a bit of extra annotation
> with any of
> them, even if each annotation is concise. It ends
> easier to just
> put verbs in your URIs, where it should be just as
> easy to do it
> properly.
> 
> I guess this would be a special kind of controller
> base class?
> I should really take the time out to do a deep dive
> on Catalyst
> so I can sort out its taxonomy in my head and hack
> out some
> actual code…
> 
> Regards,
> -- 
> Aristotle Pagaltzis // <http://plasmasturm.org/>
> 
> _______________________________________________
> List: Catalyst at lists.rawmode.org
> Listinfo:
> http://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive:
>
http://www.mail-archive.com/catalyst@lists.rawmode.org/
> Dev site: http://dev.catalyst.perl.org/
> 



 
____________________________________________________________________________________
Sponsored Link

$200,000 mortgage for $660/ mo - 
30/15 yr fixed, reduce debt - 
http://yahoo.ratemarketplace.com



More information about the Catalyst mailing list