Plack::Middleware::FormatOutput - Format output struct by Accept header.
Version 0.02
use Plack::Middleware::FormatOutput; builder { enable 'FormatOutput'; mount "/api" => sub { return {'link' => 'content'} }; };
The Middleware formats output perl struct by "Accept" header param or by format param in URL.
You can get json when define:
Accept header application/json
or
Add ?format=application/json to URL
For complete RestAPI in Perl use:
Plack::Middleware::RestAPI
Plack::Middleware::ParseContent
application/json
text/yaml
text/plain
text/html - it uses Rest::HtmlVis as default formater if installed
Specify if and how returned content should be formated in browser.
For example:
use Plack::Middleware::FormatOutput; use My::HTML builder { enable 'FormatOutput', mime_type => { 'text/html' => sub{ My::HTML::Parse(@_) } }; mount "/api" => sub { return {'link' => 'content'} }; };
Define parameters for Rest::HtmlVis.
use Plack::Middleware::FormatOutput; builder { enable 'FormatOutput', htmlvis => { links => 'My::Links' }; mount "/api" => sub { return {'links' => 'content'} }; };
http://psgirestapi.dovrtel.cz/
Vaclav Dovrtel, <vaclav.dovrtel at gmail.com>
<vaclav.dovrtel at gmail.com>
Please report any bugs or feature requests to github repository.
Inspired by https://github.com/towhans/hochschober
https://github.com/vasekd/Plack-Middleware-FormatOutput
Copyright 2015 Vaclav Dovrtel.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Plack::Middleware::FormatOutput, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Plack::Middleware::FormatOutput
CPAN shell
perl -MCPAN -e shell install Plack::Middleware::FormatOutput
For more information on module installation, please visit the detailed CPAN module installation guide.