ge Plack::ResponseHelper::JSON;
use strict;
use warnings;
use JSON;
use Plack::Response;
sub helper {
return sub {
my $r = shift;
my $body = encode_json $r;
my $response
->content_type('application/json; charset=utf-8');
$response->body($body);
return $response;
};
}
1;
__END__
=head1 NAME
Plack::ResponseHelper::JSON
=head1 SEE ALSO
Plack::Re
it as a micro-framework:
in app.psgi
use Plack::Request;
use Plack::ResponseHelper json => 'JSON',
text => 'Text';
my $app = sub {
my $env = shift
$form);
};
somewhere in your controllers
sub my_controller {
...
return json => {status => 'ok', data => [1, 2, 3]};
}
# or
sub dummy_controller {
return
s Plack's specifics.
Bundled with
L<Plack::ResponseHelper::Attachment>,
L<Plack::ResponseHelper::JSON>,
L<Plack::ResponseHelper::Redirect>,
L<Plack::ResponseHelper::Text>.
=head1 METHODS
=head2 use