[Catalyst] DBIC-API: building queries from chained uris

Ian Sillitoe ian at sillit.com
Wed Jun 27 11:10:33 GMT 2012


Hi,

I'm using Catalyst-Controller-DBIC-API to provide some RESTful webservices
- at the moment it is set up as per the cpan docs:

/api/rest/superfamily            # lists all "superfamily" objects
/api/rest/superfamily/1.10.8.10  # list a single "superfamily" object
/api/rest/domain                 # lists all "domain" objects
/api/rest/domain/1abcA01         # list a single "domain" object

NB: a "domain" belongs to a "superfamily".

I also want to set up some chained uris to make common queries more
readable and avoid typos, e.g.

# list all the domains in superfamily "1.10.8.10"
/api/rest/superfamily/1.10.8.10/domain

I couldn't see any docs that specifically deal with this - so at the moment
I'm working on the basis that I need create an end point for the above path
and turn it into a request for:

/api/rest/domain?search.superfamily_id=3D1.10.8.10

Since I need to mess with the request params I figured I need to do this
via a full SubRequest - something like...

package MyApp::Controller::API::REST::Superfamily::Domain;
use Moose;
BEGIN { extends 'Catalyst::Controller' }

sub base :Chained( '/api/rest/superfamily/base_with_id' ) PathPart(
'domain' ) CaptureArgs(0) {
        my ($self, $c) =3D @_;
}

sub list :Chained( 'base') PathPart('') Args(0) {
        my ($self, $c) =3D @_;
        my $res =3D $c->subreq_res(
                        $c->uri_for_action( '/api/rest/domain/list_objects'
)->path,
                        {},
                        {
                                'search.superfamily_id' =3D>
$c->stash->{superfamily_id},
                        });

        $c->response->headers( $res->headers );
        $c->response->body( $res->body );
}


However, this seems a bit messy (although perhaps marginally less messy
then overwriting the current request params, then forwarding) - is there a
better way of achieving this kind of thing?

Many thanks,

-- =

Ian Sillitoe
Orengo Group, Structural and Molecular Biology
University College London
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20120627/1cb1f=
13a/attachment.htm


More information about the Catalyst mailing list