[Catalyst] Catalyst::Action::REST

Jonathan Rockway jon at jrock.us
Mon Nov 20 16:43:39 GMT 2006


Adam Jacob wrote:
> After much discussion, I've unleased Catalyst::Action::REST upon an
> unsuspecting CPAN.  It's an attempt at making RESTful web applications
> in Catalyst easier (they were already pretty easy.) The basics:
> 
> 1) Uses an Action class to extend Catalyst's dispatch mechanism to allow
> for different methods based on the HTTP Method.  For example:
> 
> sub foo :Local :ActionClass('REST') {}
> 
> sub foo_GET {}
> 
> sub foo_POST {}
> 
> sub foo_DELETE {}

It just occurred to me (after reading Aristotle's post below), that it
might be a good idea to provide verbs for dumb HTTP clients (web
browsers).  Example:

   sub foo :Local :ActionClass('REST') {}
   sub foo_DELETE {}

This would create URIs:

foo
foo/delete

so that a GET (or POST, which might be better in this case) request to
foo/delete would do the same thing as a real DELETE request.  This means
that your AJAX and smart HTTP clients could do a DELETE /foo/bar, but
you could still have a link in the browser to /foo/delete/bar.

(Maybe foo/arg0/.../argn/delete would look nicer than
foo/delete/arg0/.../argn ?)

Also, is it currently possible to do something like this?

   sub foo :Local :ActionClass('REST'){
     my ($self, $c) = @_
     do_something_before_method_specific_action();
     $self->next::method(@_);
     do_something_after_method_specific_action();
   }

As always, thanks for writing this.  I look forward to using it for
something ;)

-- 
package JAPH;use Catalyst qw/-Debug/;($;=JAPH)->config(name => do {
$,.=reverse qw[Jonathan tsu rehton lre rekca Rockway][$_].[split //,
";$;"]->[$_].q; ;for 1..4;$,=~s;^.;;;$,});$;->setup;



More information about the Catalyst mailing list