[Catalyst] Mapping parameters for web services

Bill Moseley moseley at hank.org
Mon Oct 22 23:20:09 GMT 2007


I'm looking for suggestions how to best map XMLRPC request parameters into
the params and arguments that my existing (web) controllers are
expecting.


I have a number of controllers that I'd like to expose for web
services.  The C::P::Server::XMLRPC plugin makes this easy since one
can add :XMLRPC to any existing controller to expose it.

My controllers tend to be thin -- that is they don't fetch every bit
of data that the View might display.  Some of that work is left to the
templates.  So, for XMLRPC I also have a separate View that prepares
any data needed for the response.  This view is called instead for
XMLRPC requests.

Frankly, feels a bit dirty but I'm doing basically:

    sub process {
        my ( $self, $c ) = @_;
        my $method = $c->action->reverse;
        $method =~ s[/][_]g;
        $self->$method( $c ) if $self->can( $method );
    }

So, I can add a method to this view for any controller that needs
extra help preparing the XMLRPC response.

So, on to my question:

The parameters and arguments that come in on web requests are
different than they come in for XMLRPC  requests -- so I need to "map"
the arguments from the XMLRPC request into the arguments and
parameters as the existing controllers expect.

So, my question is *where* to do that?  It's application-specific
so seems like something that should happen in auto().

As above, there's the View system to prepare the response.  Should I just
cheat and abuse it on requests as well?  That is:

    sub auto : Private {
        my ( $self, $c ) = @_;
        $c->forward( $c->view( 'XMLRPC::Input' ) ) if $c->is_xmlrcp;
        return 1;
    }

And then that "view" would adjust the request arguments and parameters
as needed.

What approach is recommended to map (filter?) the request based on the
action?





-- 
Bill Moseley
moseley at hank.org




More information about the Catalyst mailing list