[Catalyst] deserializing key value pairs Catalyst::Controller::REST

Hani Anani hanianani at gmail.com
Wed Jul 30 21:13:31 BST 2008


Thanks Jochen and J.Shirley,

What I was trying to do is access parameters from the URL so i could have a
REST interface, something like

http://foo.bar.com/rest/v1/db/source_destination_mapt/1/destination_account=
/2

I ended up doing something like this

sub source_destination_map :Local :ActionClass('REST') {
    my $self =3D shift;
    my $c    =3D shift;
    $c->stash(source_account =3D> shift);
    $c->stash(@_);
}

and then access the parameters from the URI like this:

sub source_destination_map_GET {
}

sub source_destination_map_POST {
    my $source_account =3D $c->{stash}->{source_account},
    my $destination_account =3D $c->{stash}->{destination_account}
}

Are there some gotchas that i might be missing as a result of handling the
parameters like this for POST/PUT requests?

-Hani

On Fri, Jul 25, 2008 at 7:23 AM, J. Shirley <jshirley at gmail.com> wrote:

> On Fri, Jul 25, 2008 at 1:48 AM, Jochen Luig <skirnir at gmx.net> wrote:
> > Hi Hani,
> >
> >> var postData =3D
> "source_account=3D1&destination_account=3D2&ingestor_id=3D10&source_id=3D=
1"
> >>
> > I think this is where it fails. As far as I can tell from your code,
> > postData should contain a JSON Object.
> > Try something like:
> >
> > var postData =3D '{ "source_account": "1", "destination_account": "2",
> > "ingestor_id": "10", "source_id": "1" }';
> >
> >
> > On another note, make sure that YAHOO.util.Connect.asyncRequest doesn't
> > mess up your request somehow (is that YUI, btw?). I've just experienced
> > the same annoyance with Dojo, whose dojo.xhrPost is not exactly fond of
> > sending JSON-Objects. It helps to look at the request itself with some
> > tool like e.g. wireshark.
> >
> > HTH,
> >
> > Jochen
> >
> >
>
> Right, Hani is sending url form encoded post body, which is not JSON
> and will fail to be processed as JSON data.  YUI can be used to
> generate your JSON data, please read the documentation at
> http://developer.yahoo.com/yui/json/
>
> asyncRequest will not mess up any requests, I've thoroughly used YUI
> in conjunction with C::C::REST and it has never let me down (IE6 is a
> different story).  As long as you stick to POST and GET, IE6 will be
> fine.
>
> Also, using Dumper inside of your controller is not recommended,
> simply use the $c->log->_dump command.  Additionally, using
> $c->req->body is what C::C::REST uses, and after the deserialization
> the data will be in $c->req->data and a simple:
>  $c->log->_dump( $c->req->data );
> shows what exactly is in the request data that has been deserialized for
> use.
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20080730/499ef=
326/attachment.htm


More information about the Catalyst mailing list