[Catalyst] Dispatching with Chained vs HTTP method
Toby Corkindale
tjc at wintrmute.net
Thu May 1 05:23:22 BST 2008
On Wed, Apr 30, 2008 at 11:24:36AM +0200, Zbigniew Lukasiak wrote:
> Hi Toby,
>
> I don't know if you are aware - but building a REST-like CRUD
> interface to DBIx::Schema is my long term goal (started with
> Catalyst::Example::InstantCRUD). Do you think we could collaborate?
Sure, if you liked.
I'm not sure I want to aim for total DBIx::Class:Schema emulation, as I think
there are many corner cases which could start getting hard to implement /well/.
I'd rather approach creating something which does a sub-set of the features,
but does them well. For instance, how would you handle transactions? Or
specifying complex searches with aggregate clauses and self-joins? Those would
seem to be more suited to an RPC protocol rather than an object-based REST
situation. I think?
The system I have so far works quite well for find and search, and I have a
client library which re-vivifies stuff back into Perl DBIC-like objects..
So in theory you can have an application which can operate upon a local
database, OR a remote database, transparently. (As long as it only uses the
simpler DBIC methods)
I'm learning more about the innards of Catalyst and DBIx::Class in the process
too :)
Toby
> On Wed, Apr 30, 2008 at 10:26 AM, Toby Corkindale <tjc at wintrmute.net> wrote:
> > just looking for some advice on the best way to do something..
> >
> > So I wrote a controller class using Chained that basically auto-converts any
> > DBIx::Schema (which includes a tiny extra base class itself) into a REST API..
> > Well, a simple one anyway - it supports find and search so far, and foreign
> > keys in the objects get serialised into hashes of the URIs to fetch them.
> >
> > All working nicely so far, but this is all for GET queries.
> >
> > But the behaviour should be different depending upon whether you
> > GET /item/1234
> > or
> > DELETE /item/1234
> > etc.
> >
> > I was thinking something like this: (Abbreviated code below)
> >
> > ------------
> > sub item_by_id : Chained CaptureArgs(2) {
> > my ($self, $c, $type, $id) = @_;
> > $c->stash->{item} = $c->model("DB:$type")->find($id);
> > }
> >
> > sub delete : Chained('item_by_id') Args ActionClass('MethodDELETE') {
> > my ($self, $c) = @_;
> > $c->stash->{item}->delete;
> > }
> >
> > sub modify : Chained('item_by_id') Args ActionClass('MethodPUT') {
> > my ($self, $c) = @_;
> > $c->stash->{item}->update($c->request->params);
> > }
> > ------------
> > Then the appropriate ActionClasses would check if the $c->req->method eq 'GET'
> > or 'DELETE' or whatever.
> >
> > But I was just wondering if you had other ideas, and if using ActionClasses
> > with Chained actions is crackfuelled and going to lead to a world of misery and
> > pain.
> >
> > Cheers!
> > Toby
More information about the Catalyst
mailing list