I'm wrapping up a project where I do this. Here's my method
signatures. The url structure is:
/tutorials
/tutorials/*
/tutorials/*/comments
/tutorials/*/comments/*
/tutorials/*/comments/*/replies
/tutorials/*/comments/*/replies/*
#
------------------------------------------------------------------------------
sub list :Chained('/') PathPart('tutorials') Args(0) :
ActionClass('REST') {}
sub list_GET { ... }
sub list_POST { ... }
sub list_HEAD { ... }
#
------------------------------------------------------------------------------
sub find_tutorial :Chained('/') PathPart('tutorials') CaptureArgs(1)
{ ... }
#
------------------------------------------------------------------------------
sub single :Chained('find_tutorial') PathPart('') Args(0)
ActionClass('REST') { ... }
sub single_GET { ... }
sub single_POST { ... }
#
------------------------------------------------------------------------------
sub comments :Chained('find_tutorial') PathPart('comments')
Args(0) :ActionClass('REST') {}
sub comments_GET { ... }
sub comments_POST { ... }
#
------------------------------------------------------------------------------
sub find_comment :Chained('find_tutorial') PathPart('comments')
CaptureArgs(1) { ... }
#
------------------------------------------------------------------------------
sub comment :Chained('find_comment') PathPart('')
Args(0) :ActionClass('REST') {}
sub comment_GET { ... }
sub comment_POST { ... }
sub comment_DELETE {...}
#
------------------------------------------------------------------------------
sub replies :Chained('find_comment') PathPart('replies')
Args(0) :ActionClass('REST') {}
sub replies_GET { ... }
sub replies_POST { ... }
#
------------------------------------------------------------------------------
sub reply :Chained('find_comment') PathPart('replies')
Args(1) :ActionClass('REST') { ... }
sub reply_POST { ... }
sub reply_DELETE { ... }
On Jun 25, 2010, at 8:02 AM, John Lifsey - Contractor - 5595 wrote:
Is there any way to chain actions such that they can be endpoints or
intermediate steps?
For example:
I want to have a REST controller that allows these URLs to work
using ActionClass REST and Chained
http://myapp.com/car - dispatch to sub car_GET for list of cars
http://myapp.com/car/corvette - dispatch to car_GET for a single
record
http://myapp.com/car/corvette/model - dispatch to sub model_GET
chained to sub car{} for a list of corvette types
http://myapp.com/car/corvette/model/Z06 - dispatch to sub model_GET
chained to sub car{} for a single corvette type record
something like this doesn't quite work:
sub car :ActionClass('REST') Chained CaptureArgs(1) {}
sub model :ActionClass('REST') Chained('car') Args(1) {}
So my question: Is there a Chained incantation to allow all of the
following to be endpoints?
/car
/car/aCarID
/car/aCarID/model
/car/aCarID/model/aModelID
Or am I just DoingItWrong all together?
_______________________________________________
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/
_______________________________________________
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/