NAME
Plack::Middleware::FormatOutput - Format output struct by Accept header.
VERSION
Version 0.02
SYNOPSIS
use Plack::Middleware::FormatOutput;
builder {
enable 'FormatOutput';
mount "/api" => sub { return {'link' => 'content'} };
};
DESCRIPTION
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
CONSTANTS
DEFAULT MIME TYPES
application/json
text/yaml
text/plain
text/html - it uses HTML::Vis as default formater if installed
PARAMETERS
mime_type
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'} };
};
htmlvis (if HTML::Vis is installed)
Define parameters for HTML::Vis.
For example:
use Plack::Middleware::FormatOutput;
builder {
enable 'FormatOutput', htmlvis => {
links => 'My::Links'
};
mount "/api" => sub { return {'link' => 'content'} };
};
TUTORIAL
http://psgirestapi.dovrtel.cz/
AUTHOR
Vaclav Dovrtel, <vaclav.dovrtel at gmail.com>
BUGS
Please report any bugs or feature requests to github repository.
ACKNOWLEDGEMENTS
Inspired by https://github.com/towhans/hochschober
REPOSITORY
https://github.com/vasekd/Plack-Middleware-FormatOutput
LICENSE AND COPYRIGHT
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.