ed content types (major portions only!)
set( 'MREST_SUPPORTED_CONTENT_TYPES', [
'application/json',
] );
# MREST_CACHE_ENABLED
# set to 0 to include response headers telling clients not to c
;
use App::CELL qw( $log );
use File::Spec;
use JSON;
use Params::Validate qw( :all );
use Pod::Simple::HTML;
use Pod::Simple::Text;
our $JSON = JSON->new->allow_nonref->convert_blessed->utf8->pret
rts:
=over
=item C<$JSON> (singleton)
=item C<pod_to_html> (function)
=item C<pod_to_text> (function)
=back
=cut
use Exporter qw( import );
our @EXPORT_OK = qw(
$JSON
pod_to_html
p
tus;
use Data::Dumper;
use JSON;
use Params::Validate qw( :all );
use Plack::Session;
use Try::Tiny;
use Web::MREST::InitRouter qw( $router );
use Web::MREST::Util qw( $JSON );
# methods/attributes n
$declared_status->payload->{'permanent'} = $pt ? JSON::true : JSON::false;
} else {
$declared_status->payload->{'permanent'} = JSON::true;
}
} else {
#
e undef
permanent => ( $ARGS{'permanent'} )
? JSON::true
: JSON::false,
},
);
}
# add standard properties to the p
ructions for reporting bugs in Web::MREST',
documentation => <<'EOH',
=pod
Returns a JSON structure containing instructions for reporting bugs.
EOH
},
# configinfo
qeuest for one of
these subresources, including the resource name in the request
entity as a bare JSON string (i.e. in double quotes).
EOH
},
# docu/pod
'docu/pod' =>
handler => {
POST => 'handler_echo',
},
cli => 'echo [$JSON]',
description => 'Echo the request body',
documentation => <<'EOH',
=pod
od: POST
URI: http://myapp.example.com/
Header: Accept: application/json
Body: {
"command" : "employee.insert",
"
}
Example HTTP response:
Status code: 200 OK
Content-Type: application/json
Body: {
"status" : {
"level" : "ERROR
t step, which Richardson calls "Many URIs, one HTTP method", involves
moving some part of the XML/JSON body into the URI. Though this step might seem
insignificant, calling it "revolutionary" would be
site );
use Data::Dumper;
use Try::Tiny;
use Web::Machine::FSM::States;
use Web::MREST::Util qw( $JSON );
use parent 'Web::MREST::Resource';
=head1 NAME
Web::MREST::Entity - Methods for dealing
ing format:
[
{ 'text/html' => 'method_for_html' },
{ 'application/json' => 'method_for_json' },
{ 'other/mime' => 'method_for_other_mime' },
]
As you can see, this i
{ 'application/json' => 'mrest_generate_response_json' },
];
}
=head2 mrest_generate_response_html
Normally, clients will communicate with the server via
'_render_response_json', but humans ne
ta::Dumper;
use File::HomeDir;
use HTTP::Request;
use JSON;
use Log::Any::Adapter;
use Params::Validate qw( :all );
use Plack::Test;
use Test::JSON;
use Test::More;
use Try::Tiny;
use Web::Machine;
us
ameters were loaded' );
is_deeply( [ $site->MREST_SUPPORTED_CONTENT_TYPES ], [ [ 'application/json' ] ],
'configuration parameters loaded?' );
# set debug mode
$log->debug_mode( $
=head2 status_from_json
L<Web::MREST> is designed to return status objects in the HTTP response entity.
Before inclusion in the response, the status object is converted to JSON. This
routine goes t
obtained using C<curl>:
curl -v http://localhost:5000/ -X GET -H "Content-Type: application/json"
For more information on using the CLI client, see L<Web::MREST::CLI>.
=head1 DESCRIPTION
MR
value), the handler
is expected to return a C<App::CELL::Status> object. This object (rendered in
JSON) becomes the response entity unless overrided by a declared status (see
C<mrest_declare_status> i
hat is returned, but a JSON
representation of its underlying data structure. From this, the object can
easily be reconstituted on the client side by doing
my $status = $JSON->decode( $response_en