in reply to Re^2: change serializer in Dancer2 according to request param
in thread change serializer in Dancer2 according to request param
Hi,
No. Serializer is too much magic for me, cant hunt all the docs to figure it out, so why bother
#!/usr/bin/perl -- use strict; use warnings; use Dancer2; sub con_serv { my( $type, $ref ) = @_; content_type('text/x-json'); require JSON::MaybeXS; return JSON::MaybeXS::encode_json($ref); } get '/always/json' => sub { con_serv( 'json', { get => '/always/json' + } ); }; get '/:type' => sub { con_serv( request->params->{type} , { get + => '/:type' } ); }; get '/' => sub { ' <html> <pre> <a href="/">/</a> <a href="/always/json">/always/json</a> <a href="/json">/json</a> ' }; dance; __END__
|
|---|