Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Dancer2 serializer mutable

by perl_help27 (Acolyte)
on Nov 08, 2018 at 20:30 UTC ( #1225456=perlquestion: print w/replies, xml ) Need Help??
perl_help27 has asked for the wisdom of the Perl Monks concerning the following question:

hello monks, I am trying to run this basic app in perl:
use Dancer2; set serializer => 'Mutable'; get '/user/:id' => sub { my $id = params->{id}; return { id => $id, name => 'frank' }; } dance;
I then call this url curl -H 'Accept-Type: text/xml' http://localhost:5000/user/1 I expect it to return <data name="franck" id="1" /> But instead I am receiving this error:
{"id" => 1,"name" => "frank"} did not pass type constraint "Value" (i +n $self->{"content"}) "Value" is defined as: (defined($_) and not ref($_)) in /usr/local +/share/perl5/Dancer2/Core/ l. 1473
I am running hopeless!! Any help would do. Thanks

Replies are listed 'Best First'.
Re: Dancer2 serializer mutable
by choroba (Bishop) on Nov 08, 2018 at 21:22 UTC
    Note that XML isn't supported by Dancer2::Serializer::Mutable, it handles JSON, YAML, and Data::Dumper only.

    It works for me when I specify

    curl -H 'Accept: application/json' http://localhost:3000/user/1

    i.e. I use Accept instead of Accept-Type (Content-Type works, too), and I switch to a supported output format.

    Update: The code mentions XML, but it seems to treat it the same way as HTML, i.e. it needs a template to fill with the data. I tried to create a new XML serializer, but I don't understand all the details, so I wasn't successful.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      Thank you LOTS for your answer... this call works however curl -H 'Accept: text/x-yaml' http://localhost:3000/user/1 doesn't return anything either:S do you know why?
        It doesn't return anything to me, either. Maybe a specific YAML library is needed? You can always report a bug against Dancer2.

        ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re: Dancer2 serializer mutable
by MrCromeDome (Deacon) on Nov 14, 2018 at 22:57 UTC
    Hey, good news! This should be possible in the newly-released 0.207000 release of Dancer2. Contact me with any issues.

      I was actually impressed and pleasantly surprised that Dancer did not support XML, FWIW. Oh, wells.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1225456]
Front-paged by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2019-01-16 03:46 GMT
Find Nodes?
    Voting Booth?
    After Perl5, I'm mostly interested in:

    Results (274 votes). Check out past polls.