On 2013-02-25 08:44, Francisco Obispo wrote:
> 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:
>
>
> allow_callback 0
> expose_stash data
>
>
> 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
You missed his point, he isn't for a different way to implement his
webservice but a way to use it in his browser.
>
>
>
>
>
>
>
>
>
>
> On Feb 24, 2013, at 11:13 PM, Jean-Marc Choulet 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
You have to do a background request mostly known as AJAX. The technical
correct term is XMLHTTPRequest [1].
jQuery has a method for it [2].
If you're using Firefox I recommend installing the Firebug addon which
can be used to easily view the request and response.
[1] http://www.w3.org/TR/XMLHttpRequest/
[2] http://api.jquery.com/jQuery.get/
>>
>> ___
>> List: Catalyst@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/
> Francisco Obispo
> Director of Applications and Services - ISC
> email: fobi...@isc.org
> Phone: +1 650 423 1374 || INOC-DBA *3557* NOC
> PGP KeyID = B38DB1BE
>
>
> ___
> List: Catalyst@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/
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be
privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
___
List: Catalyst@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/