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

A. Pagaltzis pagaltzis at gmx.de
Mon Nov 20 15:02:29 GMT 2006


* 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.

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/>



More information about the Catalyst mailing list