Dancer2::Plugin::SendAs
Fellow Dancers, At the Dancer conference in Vienna last week, Dancer2::Plugin::SendAs was developed and released. This plugin makes it easy to return either serialized content or HTML from a route. Here's the synopsis: use Dancer2; use Dancer2::Plugin::SendAs; set serializer => 'YAML'; set template => 'template_toolkit'; # returns HTML content, though YAML serializer is configured get '/html' => sub { send_as html => template 'foo'; }; # returns JSON content, even with YAML serializer configured get '/json/**' => sub { send_as json => splat; # JSON, not YAML! }; Sawyer and I briefly discussed if this should be core functionality during the conference. We decided to release it as a plugin and review moving it to core if other Dancers find this functionality useful. Grab it from CPAN and give it a workout [1]. If send_as solves an issue for your apps or makes your code simpler, let us know (responding here if fine). If there is enough [2] feedback that this is generally useful, we'll make it core functionality. Happy dancing! Russell. [1] I'm doing some post-conference travel, so haven't used it in anger myself yet. [2] Don't ask me to quantify "enough" ;)
On Oct 27, 2015, at 8:35 AM, Russell Jenkins <russell.jenkins@strategicdata.com.au> wrote:
Fellow Dancers,
At the Dancer conference in Vienna last week, Dancer2::Plugin::SendAs was developed and released. This plugin makes it easy to return either serialized content or HTML from a route. Here's the synopsis:
use Dancer2;
Nice work Russell I love seeing fruits of the conference, I hope you are enjoying the rest of your travels. -Sam
2015-10-27 14:35 GMT+02:00 Russell Jenkins <russell.jenkins@strategicdata.com.au>:
Sawyer and I briefly discussed if this should be core functionality during the conference. We decided to release it as a plugin and review moving it to core if other Dancers find this functionality useful.
I really liked this feature in D1, even I did not use it. So I like it in D2 (as plugin) too. It brings back flexible possibility of content negotiation. I missed it (theoretically). But is D2 aimed for webapps or webservices? If equally for both, then it should find it's place in core, IMHO. Wbr, -- Kõike hääd, Gunnar
Hi guys. My two cents : the fact the old behavior broke some serializers is indeed a problem. Also, given that D2 provides a clean scoping (thanks Apps!) it's not such a problem we're now stricter. If you want both, just put the serializers in an app and you're done. Bonus side effect : your code is now cleaner :-) So, to me, this is the right thing to do for D2. Le mar. 27 oct. 2015 18:35, WK <wanradt@gmail.com> a écrit :
2015-10-27 14:35 GMT+02:00 Russell Jenkins <russell.jenkins@strategicdata.com.au>:
Sawyer and I briefly discussed if this should be core functionality during the conference. We decided to release it as a plugin and review moving it to core if other Dancers find this functionality useful.
I really liked this feature in D1, even I did not use it. So I like it in D2 (as plugin) too. It brings back flexible possibility of content negotiation. I missed it (theoretically). But is D2 aimed for webapps or webservices? If equally for both, then it should find it's place in core, IMHO.
Wbr, -- Kõike hääd,
Gunnar _______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
On 2015-10-27 02:28 PM, Alexis Sukrieh wrote:
Also, given that D2 provides a clean scoping (thanks Apps!) it's not such a problem we're now stricter. If you want both, just put the serializers in an app and you're done.
Just to illustrate (as we are discussing something along those lines on the dev side), that could look like: use 5.20.0; package MyApp::Templatey { use Dancer2; set template => 'Simple'; get '/templated' => sub { template "templated" }; } package MyApp::Serializish { use Dancer2; set serializer => 'JSON'; get '/serialized' => sub { $some_struct }; } The final application will have the routes '/templated' and '/serialized', and they will both act as per their names. The end-user will never know, but for the developer the existence of both sub-apps mean that the behaviours are nicely segregated. Joy, `/anick
Very nice! From: dancer-users [mailto:dancer-users-bounces@dancer.pm] On Behalf Of Russell Jenkins Sent: 27 October 2015 12:36 To: dancer-users@dancer.pm Subject: [dancer-users] Dancer2::Plugin::SendAs Fellow Dancers, At the Dancer conference in Vienna last week, Dancer2::Plugin::SendAs was developed and released. This plugin makes it easy to return either serialized content or HTML from a route. Here's the synopsis: use Dancer2; use Dancer2::Plugin::SendAs; set serializer => 'YAML'; set template => 'template_toolkit'; # returns HTML content, though YAML serializer is configured get '/html' => sub { send_as html => template 'foo'; }; # returns JSON content, even with YAML serializer configured get '/json/**' => sub { send_as json => splat; # JSON, not YAML! }; Sawyer and I briefly discussed if this should be core functionality during the conference. We decided to release it as a plugin and review moving it to core if other Dancers find this functionality useful. Grab it from CPAN and give it a workout [1]. If send_as solves an issue for your apps or makes your code simpler, let us know (responding here if fine). If there is enough [2] feedback that this is generally useful, we'll make it core functionality. Happy dancing! Russell. [1] I'm doing some post-conference travel, so haven't used it in anger myself yet. [2] Don't ask me to quantify "enough" ;)
This looks cool. What are the options for send_as? I have a dataset I send as JSON, but the page that grabs it converts it to csv for the end user to load into a spreadsheet. I would suppose YAML is an option for sending data, but are there others such as CSV? --john On Tue, October 27, 2015 6:35 am, Russell Jenkins wrote:
Fellow Dancers,
At the Dancer conference in Vienna last week, Dancer2::Plugin::SendAs was developed and released. This plugin makes it easy to return either serialized content or HTML from a route. Here's the synopsis:
use Dancer2; use Dancer2::Plugin::SendAs;
set serializer => 'YAML'; set template => 'template_toolkit';
# returns HTML content, though YAML serializer is configured get '/html' => sub { send_as html => template 'foo'; };
# returns JSON content, even with YAML serializer configured get '/json/**' => sub { send_as json => splat; # JSON, not YAML! };
Sawyer and I briefly discussed if this should be core functionality during the conference. We decided to release it as a plugin and review moving it to core if other Dancers find this functionality useful.
Grab it from CPAN and give it a workout [1]. If send_as solves an issue for your apps or makes your code simpler, let us know (responding here if fine). If there is enough [2] feedback that this is generally useful, we'll make it core functionality.
Happy dancing! Russell.
[1] I'm doing some post-conference travel, so haven't used it in anger myself yet. [2] Don't ask me to quantify "enough" ;)
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
participants (7)
-
Alexis Sukrieh -
John McDermott -
Russell Jenkins -
Sam Batschelet -
WK -
Yanick Champoux -
Zahir Lalani