Skip to content

vasekd/Plack-Middleware-FormatOutput

Repository files navigation

NAME

Plack::Middleware::FormatOutput - Format output struct by Accept header.

SYNOPSIS

    use Plack::Middleware::FormatOutput;

    builder {
            enable 'FormatOutput';
            mount "/api" => sub { return [200, undef, {'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::App::REST
  • Plack::Middleware::ParseContent

CONSTANTS

DEFAULT MIME TYPES

  • application/json
  • text/yaml
  • text/plain
  • text/html - it uses Rest::HtmlVis as default formatter 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 [200, undef, {'link' => 'content'}] };
    };

htmlvis (if Rest::HtmlVis is installed)

Define parameters for Rest::HtmlVis.

For example:

    use Plack::Middleware::FormatOutput;

    builder {
            enable 'FormatOutput', htmlvis => {
                    links => 'My::Links'
            };
            mount "/api" => sub { return [200, undef, {'links' => 'content'}] };
    };

TUTORIAL

http://psgirestapi.dovrtel.cz/

AUTHOR

Václav Dovrtěl vaclav.dovrtel@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

COPYRIGHT

Copyright 2015- Václav Dovrtěl

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

About

Format output struct by Accept header.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages