[Catalyst] Index action using Catalyst::Controller::REST - Is it possible?

Devin Austin devin.austin at gmail.com
Tue Apr 26 18:30:27 GMT 2011


On Tue, Apr 26, 2011 at 11:37 AM, Kyle Hall <kyle.m.hall at gmail.com> wrote:

> Hello all,
>  I'm trying to write a REST service using the REST controller. The
> problem I'm running into is I can't seem to use 'index' as I can with
> the standard catalyst controller. I would like my URIs to look like
> /api/rest/documents, /api/rest/staff and so on. From these paths I
> would like to do the standard GET, PUT, POST and DELETE calls.
>
> However, if I create the controller
> MyApp::Controller::API::REST::Documents, and I try this:
>   sub index : Local : ActionClass('REST') {}
> The system loads this as the path action /api/rest/documents/index.
>
> Any idea what I'm doing wrong?
>
> Thanks,
> Kyle
>
> http://www.kylehall.info
> Mill Run Technology Solutions ( http://millruntech.com )
> Crawford County Federated Library System ( http://www.ccfls.org )
> Meadville Public Library ( http://www.meadvillelibrary.org )
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>

Have you considered using Chained for this?  Your URL structure looks like
it would lend itself nicely to that.

You'd do something like:

package MyApp::Web::Controller::API::REST::Documents;
use ...
BEGIN { extends 'MyApp::Web::Controller::API::REST' }

# chaining to '.' allows you to have a chain root in a parent class
# that you can chain off of and inherit functionality from (see
http://search.cpan.org/~bobtfish/Catalyst-Runtime-5.80032/lib/Catalyst/Disp=
atchType/Chained.pm#Attributesunder
"Chained")
# also, specify the path part here, so index acts how you want it to as an
end point.
sub documents : Chained('.') PathPart('documents') CaptureArgs(0) {
  my ($self, $c) =3D @_;
  # do whatever document grabbing functionality you need to do here
}

sub index : Chained('documents') PathPart('') Args(0) {
  my ($self, $c) =3D @_;
  # display stuff etc
}

NOTE: This is untested code, but it SHOULD give you an idea of what to do.

-- =

Devin Austin
http://www.codedright.net
9702906669 - Cell
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20110426/827c5=
405/attachment.htm


More information about the Catalyst mailing list