in reply to Re: change serializer in Dancer2 according to request param
in thread change serializer in Dancer2 according to request param

Can you please provide me with a small example? Thank you
  • Comment on Re^2: change serializer in Dancer2 according to request param

Replies are listed 'Best First'.
Re^3: change serializer in Dancer2 according to request param
by Anonymous Monk on Apr 13, 2018 at 02:34 UTC

    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__