NAME

Hypersonic::UA::Response - HTTP response object for Hypersonic::UA

SYNOPSIS

# Response objects are returned by UA requests
my $res = $ua->get('http://example.com/api');

# Check status
print $res->status;        # 200
print $res->status_text;   # "OK"

# Check response type
if ($res->is_success) { ... }
if ($res->is_redirect) { ... }
if ($res->is_error) { ... }

# Get body
print $res->body;

# Get headers
my $headers = $res->headers;
my $ct = $res->header('Content-Type');

# Parse JSON
if ($res->is_json) {
    my $data = $res->json;
}

DESCRIPTION

Hypersonic::UA::Response represents an HTTP response. It provides methods for accessing status, headers, and body content.

METHODS

new

my $res = Hypersonic::UA::Response->new($status, \%opts);

Create a new response object.

from_raw

my $res = Hypersonic::UA::Response->from_raw($raw_http);

Parse a response from raw HTTP bytes.

status

my $code = $res->status;

Get HTTP status code (e.g., 200, 404, 500).

status_text

my $text = $res->status_text;

Get HTTP status text (e.g., "OK", "Not Found").

body

my $body = $res->body;

Get response body as string.

headers

my $headers = $res->headers;

Get all headers as hashref.

my $value = $res->header('Content-Type');

Get a single header value (case-insensitive).

content_type

my $ct = $res->content_type;

Get Content-Type header.

content_length

my $len = $res->content_length;

Get Content-Length header.

raw_headers

my $raw = $res->raw_headers;

Get raw header string.

is_success

if ($res->is_success) { ... }

True if status is 2xx.

is_redirect

if ($res->is_redirect) { ... }

True if status is 3xx.

is_error

if ($res->is_error) { ... }

True if status is 4xx or 5xx.

is_client_error

if ($res->is_client_error) { ... }

True if status is 4xx.

is_server_error

if ($res->is_server_error) { ... }

True if status is 5xx.

is_json

if ($res->is_json) { ... }

True if Content-Type indicates JSON.

json

my $data = $res->json;

Parse body as JSON (requires Cpanel::JSON::XS). Result is cached.

location

my $url = $res->location;

Get Location header (for redirects).

AUTHOR

lnation <email@lnation.org>

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.