[dancer-users] Trying to use Dancer2::Plugin::REST, what did I do wrong?

Pierre M piemas25 at gmail.com
Thu Dec 5 13:23:07 GMT 2013

Hi, here is what I'm trying to do:

package mbf;
use Dancer2;
use Dancer2::Plugin::REST;

get '/page.:format' => sub { [
        'some key' => 'value',
        'something'=> 'else',
    ] };

And when I go to
ARRAY(0x23b3880) in the browser. The data was not serialized.
What did I do wrong?

As an alternative I've done something that works:

package mbf;
use Dancer2;
use Dancer2::Serializer::JSON;

get '/page.json' => sub {
        'some key' => 'value',
        'something'=> 'else',

And in the browser I get what I expect: ["some
I would like to use use Dancer2::Plugin::REST though, to leave the choice
of format to whoever will use the API.

I noticed a detail in the module's documentation. The two examples given
    get '/user/:id.:format' => sub {
    get qr{^/user/(?<id>\d+)\.(?<format>\w+)} => sub {

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.
Any idea?

--- Pierre Masci
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20131205/dd8a5076/attachment.html>

More information about the dancer-users mailing list