Async-Microservice
view release on metacpan or search on metacpan
lib/Async/MicroserviceReq.pm view on Meta::CPAN
...
my $plack_handler_sub = sub {
my ($plack_respond) = @_;
$this_req->plack_respond($plack_respond);
...
=head1 DESCRIPTION
This is an object created for each request handled by L<Async::Microservice>.
It is passed to all request handling functions as the first argument and
it provides request information and response helper methods.
=head1 ATTRIBUTES
method
headers
path
params
plack_respond
static_dir
base_url
want_json
content
json_content
=head1 METHODS
=head2 text_plain(@text_lines)
Send text plain response.
=head2 respond($status, $headers, $payload)
Send a PSGI/Plack response.
C<$headers> must be an array reference of header key/value pairs.
If C<$payload> is not a reference, it is sent as plain text by default.
When the request C<Accept> header allows JSON and no explicit
C<Content-Type> header is already present, plain scalar payloads are wrapped
automatically as JSON:
{ "data": "..." }
For error statuses (C<< $status >= 400 >>), scalar payloads are wrapped as:
{ "error": { err_status => ..., err_msg => ... } }
If C<$payload> is a reference, it is serialized as JSON. When JSONP is
enabled and a valid callback parameter is present, the response is emitted as
C<application/javascript> instead of C<application/json>.
=head2 redirect($location_path)
Send redirect.
=head2 static_ft($file_name, $content_cb)
Send static file, can be updated/modified using optional callback.
=head2 get_pending_req
Returns number of currently pending async requests.
=cut
( run in 1.043 second using v1.01-cache-2.11-cpan-39bf76dae61 )