Plack::Middleware::FormatOutput - Format output struct by Accept header.
use Plack::Middleware::FormatOutput; builder { enable 'FormatOutput'; mount "/api" => sub { return [200, undef, {'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::App::REST
Plack::Middleware::ParseContent
application/json
text/yaml
text/plain
text/html - it uses Rest::HtmlVis as default formatter 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 [200, undef, {'link' => 'content'}] }; };
Define parameters for Rest::HtmlVis.
use Plack::Middleware::FormatOutput; builder { enable 'FormatOutput', htmlvis => { links => 'My::Links' }; mount "/api" => sub { return [200, undef, {'links' => 'content'}] }; };
http://psgirestapi.dovrtel.cz/
Václav Dovrtěl <vaclav.dovrtel@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- Václav Dovrtěl
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
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.