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

Kyle Hall kyle.m.hall at gmail.com
Wed Apr 27 12:43:40 GMT 2011


This solution works great! 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 )




On Wed, Apr 27, 2011 at 6:11 AM,  <Ian.Docherty at nomura.com> wrote:
> This is because
> sub index : Local : ActionClass('REST') {}
>
> is equivalent to
> sub index : Path('index') : ActionClass('REST') {}
>
> try
> sub index : Path('') : ActionClass('REST') {}
>
>
> From: Devin Austin [mailto:devin.austin at gmail.com]
> Sent: 26 April 2011 19:30
> To: The elegant MVC web framework
> Subject: Re: [Catalyst] Index action using Catalyst::Controller::REST - Is it possible?
>
>
> 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/DispatchType/Chained.pm#Attributes under "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) = @_;
>   # do whatever document grabbing functionality you need to do here
> }
>
> sub index : Chained('documents') PathPart('') Args(0) {
>   my ($self, $c) = @_;
>   # 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
>
>
>
> This e-mail (including any attachments) is confidential, may contain
> proprietary or privileged information and is intended for the named
> recipient(s) only. Unintended recipients are prohibited from taking action
> on the basis of information in this e-mail and must delete all copies.
> Nomura will not accept responsibility or liability for the accuracy or
> completeness of, or the presence of any virus or disabling code in, this
> e-mail. If verification is sought please request a hard copy. Any reference
> to the terms of executed transactions should be treated as preliminary only
> and subject to formal written confirmation by Nomura. Nomura reserves the
> right to monitor e-mail communications through its networks (in accordance
> with applicable laws). No confidentiality or privilege is waived or lost by
> Nomura by any mistransmission of this e-mail. Any reference to "Nomura" is
> a reference to any entity in the Nomura Holdings, Inc. group. Please read
> our Electronic Communications Legal Notice which forms part of this e-mail:
> http://www.Nomura.com/email_disclaimer.htm
>
>
> _______________________________________________
> 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/
>



More information about the Catalyst mailing list