On Tue, Apr 26, 2011 at 11:37 AM, Kyle Hall <[email protected]> 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: [email protected]
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/[email protected]/
> 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#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) = @_;
  # 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
_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to