NAME
Hijk - Specialized HTTP client
SYNOPSIS
my $res = Hijk::request({
host => "example.com",
port => "80",
path => "/flower",
query_string => "color=red"
});
die unless ($res->{status} == "200"); {
say $res->{body};
DESCRIPTION
Hijk is a specialized HTTP Client that does nothing but transporting the response body back. It does not feature as a "user agent", but as a dumb client. It is suitble for connecting to data servers transporting via HTTP rather then web servers.
Most of HTTP features like proxy, redirect, Transfer-Encoding, or SSL are not supported at all. For those requirements we already have many good HTTP clients like HTTP::Tiny, Furl or LWP::UserAgent.
FUNCTIONS
Hijk::request( $args :HashRef ) :HashRef
This is the only function to be used. It is not exported to its caller namespace at all. It takes a request arguments in HashRef and returns the response in HashRef.
The $args
request arg should contain key-value pairs from the following table. The value for host
and port
are mandatory and others are optional with default values listed below
Too keep the implementation straight-forward, Hijk does not take full URL string as input.
The value of head
is an ArrayRef of key-value pairs instead of HashRef, this way the order of headers can be maintained. For example:
head => [
"Content-Type" => "application/json",
"X-Requested-With" => "Hijk",
]
... will produce these request headers:
Content-Type: application/json
X-Requested-With: Hijk
Again, there are no extra character-escaping filter within Hijk.
The return vaue is a HashRef representing a response. It contains the following key-value pairs.
For example, to send request to http://example.com/flower?color=red
, use the following code:
my $res = Hijk::request({
host => "example.com",
port => "80",
path => "/flower",
query_string => "color=red"
});
die "Response is not OK" unless $res->{status} ne "200";
Notice that you do not need to put the leading "?"
character in the query_string
. You do, however, need to propery uri_escape
the content of query_string
.
All values are assumed to be valid. Hijk simply passthru the values without validating the content. It is possible that it constructs invalid HTTP Messages. Users should keep this in mind when using Hijk.
AUTHORS
COPYRIGHT
Copyright (c) 2013 Kang-min Liu <gugod@gugod.org>
.
LICENCE
The MIT License
DISCLAIMER OF WARRANTY
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.