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.
I hope to spend more time understanding this, but unfortunately I probably won't be able to. May I suggest taking a look at the tests and working your way back to your code? On Thu, Dec 5, 2013 at 2:23 PM, Pierre M <piema...@gmail.com> wrote: > Hi, here is what I'm trying to do: > > package mbf; > use Dancer2; > use Dancer2::Plugin::REST; > prepare_serializer_for_format; > > get '/page.:format' => sub { [ > 'some key' => 'value', > 'something'=> 'else', > ] }; > true; > > And when I go to > http://localhost:5000/page.json<http://localhost:5000/markets.json>I get > 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 { > to_json([ > 'some key' => 'value', > 'something'=> 'else', > ]); > }; > true; > > And in the browser I get what I expect: ["some > key","value","something","else"] > 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 > are: > get '/user/:id.:format' => sub { > and > 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 > > > _______________________________________________ > dancer-users mailing list > dancer-users@dancer.pm > http://lists.preshweb.co.uk/mailman/listinfo/dancer-users > >
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users