Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Dancer-Plugin-REST CPAN distribution.

Report information
The Basics
Id: 93478
Status: resolved
Priority: 0/
Queue: Dancer-Plugin-REST

People
Owner: Nobody in particular
Requestors: pierre.vigier [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Possible Bug on REST Plugin
Date: Mon, 3 Mar 2014 12:16:44 +0800
To: bug-Dancer-Plugin-REST [...] rt.cpan.org
From: Pierre VIGIER <pierre.vigier [...] gmail.com>
Download (untitled) / with headers
text/plain 2.7k
Hi, I have a strange behaviour with the Dancer::Plugin::REST, and i don't know if it is desired. First of all, i'm using a MacBook Retina, with OS X maverick, Darwin Kernel Version 13.1.0 pierre@mac:~$ perl -v This is perl 5, version 12, subversion 4 (v5.12.4) built for darwin-thread-multi-2level pierre@mac:~$ perl -MDancer::Plugin::REST -e 'print $Dancer::Plugin::REST::VERSION'; 0.07 I create a tiny Dancer app to expose my problem: #!/usr/bin/env perl use Dancer; use Dancer::Plugin::REST; set serializer => 'JSON'; prepare_serializer_for_format; resource 'tests' => get => sub { status_ok( { message => "get ok" } ); }, create => sub { status_created( { message => "create ok" } ); }, delete => sub { status_ok( { message => "ok" } ); }, update => sub { status_ok( { message => "ok" } ); }; dance; Then i launch the app from command line: pierre@mac:~/work/test$ ./app.pl Show quoted text
>> Dancer 1.3121 server 10301 listening on http://0.0.0.0:3000 >> Dancer::Plugin::REST (0.07)
== Entering the development dance floor ... Here are some curl result: pierre@mac:~$ curl http://localhost:3000/tests/1 { "message" : "get ok" } pierre@mac:~$ curl http://localhost:3000/tests/1.xml <data message="get ok" /> pierre@mac:~$ curl http://localhost:3000/tests/1 <data message="get ok" /> pierre@mac:~$ curl http://localhost:3000/tests/1.yml --- message: get ok pierre@mac:~$ curl http://localhost:3000/tests/1 --- message: get ok pierre@mac:~$ I set my default serializer to JSON, then, when i make a GET request without format extension, i retrieve some json, however, if i make a GET request with a format extension, the url without format extension use the previous explicitly requested format. If several user access my API, and they do not specify format, another user can make their content-type to change, i can use a work around by creating a hook after calling prepare_serializer_for_format, like that: #!/usr/bin/env perl use Dancer; use Dancer::Plugin::REST; set serializer => 'JSON'; prepare_serializer_for_format; hook 'before' => sub { my $format = params->{'format'}; return if defined $format; set serializer => 'JSON'; }; resource 'tests' => get => sub { status_ok( { message => "get ok" } ); }, create => sub { status_created( { message => "create ok" } ); }, delete => sub { status_ok( { message => "ok" } ); }, update => sub { status_ok( { message => "ok" } ); }; dance; Then, as i expect, i have: pierre@mac:~$ curl http://localhost:3000/tests/1 { "message" : "get ok" } pierre@mac:~$ curl http://localhost:3000/tests/1.xml <data message="get ok" /> pierre@mac:~$ curl http://localhost:3000/tests/1 { "message" : "get ok" } pierre@mac:~$ Is it a normal behaviour or do i forget something in the Plugin initialization? Thanks, Pierre
Subject: Re: [rt.cpan.org #93478] Possible Bug on REST Plugin
Date: Mon, 03 Mar 2014 14:04:03 -0500
To: bug-Dancer-Plugin-REST [...] rt.cpan.org
From: Yanick Champoux <yanick [...] babyl.dyndns.org>
Download (untitled) / with headers
text/plain 663b
On 14-03-02 11:17 PM, Pierre VIGIER via RT wrote: Show quoted text
> Is it a normal behaviour or do i forget something in the Plugin > initialization?
It's a kinda-bad behavior. What happens is that the plugin doesn't clean up after itself after a request, so the next request, if no serializer is explicitly given, will continue to use the last one picked up. Most people won't see that as they usually always call the urls with the extensions, but your use of the a default serializer tripped this corner case. Fortunately, it'll be easy to make the plugin reset everything to default once it's done. Stay tuned, a new release should come out soon. :-) Thanks! `/anick


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.