Apache2-API
view release on metacpan or search on metacpan
lib/Apache2/API.pm view on Meta::CPAN
sub reply
{
my $self = shift( @_ );
my( $code, $ref );
my $use_rfc_error = $self->{use_rfc_error} // $USE_RFC_ERROR;
# rfc9457 standard for REST API error response: <https://www.rfc-editor.org/rfc/rfc9457.html>
# Legacy JSON payload like Google, Twitter, Facebook
# Modern REST APIs now uses rfc9457 with a flattened payload.
# When the use_rfc_error object property is true, we use rfc9457 flattened error, this will produce something like:
# {
# error => 'not_found',
# status => 404,
# title => 'Not found!',
# detail => q{The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.},
# locale => 'en-US',
# type => 'https://api.example.com/problems/not-found',
# }
# otherwise, the legacy approach would be:
# {
# error =>
# {
lib/Apache2/API/Request.pm view on Meta::CPAN
my $cookie = $req->cookie( $name );
# Cookie::Jar object
my $jar = $req->cookies;
# get data string sent by client
my $data = $req->data;
my $formatter = $req->datetime;
my $decoded = $req->decode( $string );
my $do_not_track = $req->dnt;
my $encoded = $req->encode( $string );
$req->discard_request_body(1);
my $document_root = $req->document_root;
my $url = $req->document_uri;
# APR::Table object
my $hash_ref = $req->env;
my $headers = $req->err_headers_out;
lib/Apache2/API/Status.pm view on Meta::CPAN
our $STATUS_TO_TYPE =
{
301 => "moved_permanently",
302 => "moved_temporarily",
307 => "redirect_temporarily",
308 => "redirect_permanent",
400 => "bad_request",
401 => "unauthorized",
402 => "payment_required",
403 => "forbidden",
404 => "not_found",
405 => "method_not_allowed",
406 => "not_acceptable",
407 => "proxy_authentication_required",
408 => "request_time_out",
409 => "conflict",
410 => "gone",
411 => "length_required",
412 => "precondition_failed",
413 => "request_entity_too_large",
414 => "request_uri_too_large",
415 => "unsupported_media_type",
416 => "range_not_satisfiable",
417 => "expectation_failed",
422 => "unprocessable_entity",
423 => "locked",
424 => "failed_dependency",
425 => "too_early",
426 => "upgrade_required",
429 => "too_many_requests",
431 => "request_header_fields_too_large",
451 => "unavailable_for_legal_reasons",
500 => "internal_server_error",
501 => "not_implemented",
502 => "bad_gateway",
503 => "service_unavailable",
504 => "gateway_timeout",
505 => "http_version_not_supported",
506 => "variant_also_varies",
507 => "insufficient_storage",
508 => "loop_detected",
};
# Missing constants in Apache2::Const
my $additions =
{
103 => 'EARLY_HINTS',
418 => 'I_AM_A_TEA_POT',
lib/Apache2/API/Status.pm view on Meta::CPAN
Provided with a 3-digits HTTP code and an optional language code such as C<en_GB> and this will return the status message in its localised form.
This is useful to provide response to error in the user preferred language. L<Apache2::API/reply> uses it to set a json response with the HTTP error code along with a localised status message.
If no language code is provided, this will default to C<en_GB>.
See L</supported_languages> for the supported languages.
=head2 status_to_type
Provided with a status code, such as C<404>, and this returns a status type such as C<not_found>.
This is used to build a rfc9457 compliant error.
=head2 supported_languages
This will return a sorted array reference of support languages for status codes.
The following language codes are currently supported: de_DE (German), en_GB (British English), fr_FR (French), ja_JP (Japanese), ko_KR (Korean), ru_RU (Russian) and zh_TW (Traditional Chinese as spoken in Taiwan).
Feel free to contribute those codes in other languages.
( run in 0.974 second using v1.01-cache-2.11-cpan-39bf76dae61 )