The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Net::API::REST::Status - Apache2 Status Codes

SYNOPSIS

    say $Net::API::REST::Status::CODES->{429};
    # returns Apache constant Apache2::Const::HTTP_TOO_MANY_REQUESTS

    say $Net::API::REST::Status::HTTP_CODES->{fr_FR}->{429} # Trop de requête
    # In Japanese: リクエスト過大で拒否した
    say $Net::API::REST::Status::HTTP_CODES->{ja_JP}->{429}

But maybe more simply:

    my $status = Net::API::REST::Status->new;
    say $status->status_message( 429 => 'ja_JP' );
    # Or without the language code parameter, it will default to en_GB
    say $status->status_message( 429 );

    # Is success
    say $status->is_info( 102 ); # true
    say $status->is_success( 200 ); # true
    say $status->is_redirect( 302 ); # true
    say $status->is_error( 404 ); # true
    say $status->is_client_error( 403 ); # true
    say $status->is_server_error( 501 ); # true

VERSION

    v0.200.3

DESCRIPTION

This module allows the access of Apache2 http constant using their numeric value, and also allows to get the localised version of the http status for a given code for currently supported languages: fr_FR (French), en_GB (British English) and ja_JP (Japanese)

It also provides some functions to check if a given code is an information, success, redirect, error, client error or server error code.

METHODS

init

Creates an instance of Net::API::REST::Status and returns the object.

convert_short_lang_to_long

Given a 2 characters language code (not case sensitive) and this will return its iso 639 5 characters equivalent for supported languages.

For example:

    Net::API::REST::Status->convert_short_lang_to_long( 'zh' );
    # returns: zh_TW

is_client_error

Returns true if the 3-digits code provided is between 400 and 500

is_error

Returns true if the 3-digits code provided is between 400 and 600

is_info

Returns true if the 3-digits code provided is between 100 and 200

is_redirect

Returns true if the 3-digits code provided is between 300 and 400

is_server_error

Returns true if the 3-digits code provided is between 500 and 600

is_success

Returns true if the 3-digits code provided is between 200 and 300

status_message

Provided with a 3-digits http code and an optional language code such as 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. "reply" in Net::API::REST 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 en_GB.

See "supported_languages" for the supported languages.

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.

SEE ALSO

Apache distribution and file httpd-2.x.x/include/httpd.h

IANA HTTP codes list