Re: [Catalyst] Catalyst::Controller::REST and Serializer/Deserializer
Le 25/02/2013 09:59, Marius Olsthoorn a écrit : You can set the (de)serializer to use in the configuration. For example: package Foo::Controller::Bar; __PACKAGE__-config( 'default' = 'application/json', 'stash_key' = 'rest', 'map' = { 'text/html' = 'JSON', 'application/jsonl' = 'JSON', } ); I have mapped test/html to JSON here so it will work in the browser. Seel also: http://search.cpan.org/~bobtfish/Catalyst-Action-REST-1.06/lib/Catalyst/Action/Serialize.pm#CONFIGURATION Marius On 25 February 2013 08:13, Jean-Marc Choulet jm130...@gmail.com 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: 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/ ___ 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/ Hello Marius, Great ! That works :) Thanks you, Jean-Marc ___ 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/
Re: [Catalyst] Catalyst::Controller::REST and Serializer/Deserializer
You can set the (de)serializer to use in the configuration. For example: package Foo::Controller::Bar; __PACKAGE__-config( 'default' = 'application/json', 'stash_key' = 'rest', 'map' = { 'text/html' = 'JSON', 'application/jsonl' = 'JSON', } ); I have mapped test/html to JSON here so it will work in the browser. Seel also: http://search.cpan.org/~bobtfish/Catalyst-Action-REST-1.06/lib/Catalyst/Action/Serialize.pm#CONFIGURATION Marius On 25 February 2013 08:13, Jean-Marc Choulet jm130...@gmail.com 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: 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/ ___ 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/
Re: [Catalyst] Catalyst::Controller::REST and Serializer/Deserializer
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: 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 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 jm130...@gmail.com 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/
Re: [Catalyst] Catalyst::Controller::REST and Serializer/Deserializer
On Sun, Feb 24, 2013 at 11:13 PM, Jean-Marc Choulet jm130...@gmail.comwrote: 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... ? Do you mean adding content-type=application/json to your GET request query parameters in the browser? -- Bill Moseley mose...@hank.org ___ 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/
Re: [Catalyst] Catalyst::Controller::REST and Serializer/Deserializer
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 jm130...@gmail.com 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: 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/