[Catalyst] Tweaking REST
Christopher H. Laco
claco at chrislaco.com
Tue Jan 30 13:42:03 GMT 2007
Adam Jacob wrote:
> On Jan 29, 2007, at 12:19 PM, Christopher H. Laco wrote:
> =
>> Christopher H. Laco wrote:
>>> I'm needing to support RSS/Atom feeds of some of my cart/wishlist data.
>>> The lazy guy in me says I can just make a view or two and be done with
>>> it (Thanks for the code LTjake!). The anal retentive programmer in me
>>> says I probably really want to use C::A::REST to get the benefit of
>>> mime-type request mapping and de/serialization for other things that
>>> might come along, like json/yaml.
> =
> Adding RSS/Atom is, as you say, just adding a proper serialization class
> for the data.
> =
>>> On top of that, I want things to also work by extension: .json, .atom,
>>> .rss etc. That's where C::P::Flavour enters the picture.
> =
> I thought about that. I have never seen Catalyst::Plugin::Flavour (it
> doesn't look like it has a CPAN release, nor is it in the Catalyst
> repo.) Currently, C::A::REST supports using a content-type argument on
> GET requests to over-ride the serializer. It would be pretty simple to
> just add the logic for the extension mapping to work as well
> =
>>> As it stands now, REST JustWorks with xml/json stuff. text/html is
>>> mapped to YAML::HTML, but I want to map that to my standard TT view. As
>>> for RSS/Atom, I'd need a Serializer for them, which in the end isn't
>>> really different than writing a view.
> =
> I think you nail that problem lower down. We should totally make a
> C::A::Serialize::View.
Yeah, I eeked this out yesterday while tinkering with the idea:
> package Catalyst::Action::Serialize::View;
> use strict;
> use warnings;
> =
> BEGIN {
> use base 'Catalyst::Action';
> };
> =
> sub execute {
> my $self =3D shift;
> my ($controller, $c, $view) =3D @_;
> my $stash_key =3D $controller->config->{'serialize'}->{'stash_key'} |=
| 'rest';
> =
> if (!$c->view($view)) {
> $c->log->debug("Could not load $view, refusing to serialize");
> return 0;
> };
> =
> return $c->view($view)->process($c);
> };
> =
> 1;
There are still some issues with using views, mainly that they both
fight of setting content-type...and since REST sets it already, the view
never sets it, which is good, but also the charset=3Dutf isn't set either...
Once I get something more solid, I'll post what I have.
-=3DChris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: OpenPGP digital signature
Url : http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070130/53dd=
252f/signature.pgp
More information about the Catalyst
mailing list