Raisin::Middleware::Formatter - A parser/formatter middleware for Raisin.
version 0.94
Parses and formats the data it gets from requests and responses if it's needed.
Invokes an application route. Before doing so, it decodes the request content, if any, and negotiates an output format based on the Accept header of the request and the produces list for the target route. It post-processes the response from the endpoint using the appropriate Decoder, ensuring that it will be a valid PSGI response.
Accept
produces
Decoder
call supports deferred responses by passing the body through unmodified if it's a file handle -- i.e., the result of calling open(), an IO::Handle object, or any blessed reference that supports both getline() and close() methods.
call
open()
IO::Handle
getline()
close()
Negotiates a format from path extension, Accept header or using default format.
A precedence is following:
extension; =item * Accept header; =item * default;
In other words if an extension exists the framework doesn't look for Accept header. If the extension is not supported the framework throws an error, the same is for Accept header. Only if both extension and Accept header are not specified does it fallback to default format.
Having picked a format, the correct encoder is set in env->{'rasinx.encoder'}. Occasionally the application will want to change the format, for example to return a JSON error response from a route that normally returns plain text. To do that, change env->{'rasinx.encoder'} to the correct encoder, and make sure that the response Content-Type header matches it. It's the application's responsibility in that case to know what it's doing, and not return content that the client can't accept.
env->{'rasinx.encoder'}
Content-Type
Extracts an extension from a path, and if exists looks for a formatter.
Parses Accept header for known formatters.
Artur Khabibullin
This software is copyright (c) 2019 by Artur Khabibullin.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Raisin, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Raisin
CPAN shell
perl -MCPAN -e shell install Raisin
For more information on module installation, please visit the detailed CPAN module installation guide.