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

Pierre M piemas25 at gmail.com
Fri Dec 6 12:56:14 GMT 2013


I'm leaving for a two weeks holidays this afternoon. I will investigate
that when I'm back.

--- Pierre Masci
I check email a couple times daily; to reach me sooner, you can send me a
text message via this page: https://awayfind.com/mascip


On 5 December 2013 13:23, Pierre M <piemas25 at 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20131206/09ae616b/attachment.html>


More information about the dancer-users mailing list