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 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?