package HTTP::Throwable::JSONFactory;
# ABSTRACT: Throw exceptions with JSON bodies
$HTTP::Throwable::JSONFactory::VERSION = '0.002';
use strict;
use warnings;
use parent qw(HTTP::Throwable::Factory)
:JSONBody
);
}
1;
=pod
=encoding UTF-8
=head1 NAME
HTTP::Throwable::JSONFactory - Throw exceptions with JSON bodies
=head1 VERSION
version 0.002
=head1 SYNOPSIS
use HTTP::Throwable::JSONF
e L<HTTP::Throwable::Role::JSONBody> role, which
will generate HTTP responses with an C<application/json> content type and
encode the (optional) provided payload using L<JSON::MaybeXS>.
The C<payload
package HTTP::Throwable::Role::JSONBody;
# ABSTRACT - JSON Body
$HTTP::Throwable::Role::JSONBody::VERSION = '0.002';
use Moo::Role;
use JSON::MaybeXS;
has payload => (
is => 'ro',
);
sub body {
json with empty
# body
return "{}" unless $self->payload;
return encode_json($self->payload);
}
sub body_headers {
my ($self, $body) = @_;
return [
'Content-Type' => 'application/json
::Role::JSONBody
=head1 VERSION
version 0.002
=head1 OVERVIEW
This role does two things - accepts an optional C<payload> argument that
should be anything you can pass to L<JSON/"encode_json">, and