<div dir="ltr"><div>I'd like to say this is a bug in Dancer2::Plugin::REST but it has passing tests, so I'm not exactly sure where the problem is. I played with it for a bit and couldn't track it yet.<br><br>I hope to spend more time understanding this, but unfortunately I probably won't be able to.<br>

<br></div>May I suggest taking a look at the tests and working your way back to your code?<br><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Dec 5, 2013 at 2:23 PM, Pierre M <span dir="ltr"><<a href="mailto:piemas25@gmail.com" target="_blank">piemas25@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi, here is what I'm trying to do:<br><br>package mbf;<br>use Dancer2;<br>use Dancer2::Plugin::REST;<br>

prepare_serializer_for_format;<br><br>get '/page.:format' => sub { [<br>        'some key' => 'value',<br>

        'something'=> 'else',<br>    ] };<br>true;<br><br></div>And when I go to <a href="http://localhost:5000/markets.json" target="_blank">http://localhost:5000/page.json</a> I get <span style="text-indent:0px;letter-spacing:normal;font-variant:normal;text-align:start;font-style:normal;display:inline!important;font-weight:normal;float:none;line-height:normal;text-transform:none;font-size:medium;white-space:normal;font-family:'Times New Roman';word-spacing:0px">ARRAY(0x23b3880)</span> in the browser.<span style="text-indent:0px;letter-spacing:normal;font-variant:normal;text-align:start;font-style:normal;display:inline!important;font-weight:normal;float:none;line-height:normal;text-transform:none;font-size:medium;white-space:normal;font-family:'Times New Roman';word-spacing:0px"></span> The data was not serialized. <br>



What did I do wrong?<br><div><br></div><div>As an alternative I've done something that works:<br><br>package mbf;<br>use Dancer2;<br>use Dancer2::Serializer::JSON;<br><br>get '/page.json' => sub {<br>    to_json([<br>



        'some key' => 'value',<br>        'something'=> 'else',<br>    ]);<br>};<br>true;<br><br></div><div>And in the browser I get what I expect: <span style="text-indent:0px;letter-spacing:normal;font-variant:normal;text-align:start;font-style:normal;display:inline!important;font-weight:normal;float:none;line-height:normal;text-transform:none;font-size:medium;white-space:normal;font-family:'Times New Roman';word-spacing:0px">["some key","value","something","else"]</span></div>



<div>I would like to use use Dancer2::Plugin::REST though, to leave the choice of format to whoever will use the API.<br><br></div><div>I noticed a detail in the module's documentation. The two examples given are:<br>



<div><code>    get </code><code>'/user/:id.:format'</code> <code>=> </code><code>sub</code> <code>{<br></code></div><div><code>and<br></code></div>

<div><code>    get </code><code>qr{^/user/(?<id>\d+)\.(?<format>\w+)}</code> <code>=> </code><code>sub</code> <code>{</code></div><br></div><div>The first example is similar to my case, but not the second one. And the documentation says: "Regexp routes will use the file-extension from captures->{'format'} to determine the serialization format." Which seems to indicate that only the second use case in the documentation would work.  I tried it. It didn't work  for me either. I must be doing something wrong.<br>



Any idea?<br></div><div><br clear="all"><div><div><div dir="ltr">--- Pierre Masci<br><br></div></div>
</div></div></div>
<br>_______________________________________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
<br></blockquote></div><br></div>