This is what I usually do:
1) install Catalyst::View::JSON
2) Add the view to your app: ./script/myapp_create.pl view JSON JSON
3) in the .conf file add:
<View::JSON>
allow_callback 0
expose_stash data
</View::JSON>
4) in the controller:
If the whole controller (.pm) will return JSON data, just add this to the end:
sub end : Private {
my ( $self, $c ) = @_;
if ( $c->stash->{data} ) {
$c->forward('View::JSON');
return 1;
}
return;
}
if you want to selectively send it in a method:
sub hello : Local {
my ($self,$c) = @_;
my $data={ hello => 'world!'};
$c->stash->{data} = $data;
$c->forward('View::JSON');
return 1;
};
Hope this helps
On Feb 24, 2013, at 11:13 PM, Jean-Marc Choulet <[email protected]> wrote:
> Hello,
>
> I'm new to Catalyst and I've certainly a stupid question... I use a
> Catalyst::Controller::REST to implement a web service. My question is : How
> can I force a application/json content-type response when I ask my ws with FF
> or Chrome... ?
>
> Thanks
>
> Jean-Marc
>
> _______________________________________________
> List: [email protected]
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/[email protected]/
> Dev site: http://dev.catalyst.perl.org/
Francisco Obispo
Director of Applications and Services - ISC
email: [email protected]
Phone: +1 650 423 1374 || INOC-DBA *3557* NOC
PGP KeyID = B38DB1BE
_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/