NAME
PAGI::Test::Response - HTTP response wrapper for testing
SYNOPSIS
use PAGI::Test::Client;
my $client = PAGI::Test::Client->new(app => $app);
my $res = $client->get('/');
# Status
say $res->status; # 200
say $res->is_success; # true
# Headers
say $res->header('Content-Type'); # 'application/json'
say $res->headers->{location}; # for redirects
# Body
say $res->content; # raw bytes
say $res->text; # decoded text
say $res->json->{key}; # parsed JSON
DESCRIPTION
PAGI::Test::Response wraps HTTP response data from test requests, providing convenient accessors for status, headers, and body content.
CONSTRUCTOR
new
my $res = PAGI::Test::Response->new(
status => 200,
headers => [['content-type', 'text/plain']],
body => 'Hello',
);
Creates a new response object. Typically you don't call this directly; it's created by PAGI::Test::Client methods.
STATUS METHODS
status
my $code = $res->status;
Returns the HTTP status code (e.g., 200, 404, 500).
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.
HEADER METHODS
header
my $value = $res->header('Content-Type');
Returns the value of a header. Case-insensitive lookup. Returns undef if header not present.
headers
my $hashref = $res->headers;
Returns all headers as a hashref. Header names are lowercased. If a header appears multiple times, the last value wins.
BODY METHODS
content
my $bytes = $res->content;
Returns the raw response body as bytes.
text
my $string = $res->text;
Returns the response body decoded as text. Uses the charset from Content-Type header if present, otherwise assumes UTF-8.
json
my $data = $res->json;
Parses the response body as JSON and returns the data structure. Dies if the body is not valid JSON.
CONVENIENCE METHODS
content_type
my $ct = $res->content_type;
Shortcut for $res->header('content-type').
content_length
my $len = $res->content_length;
Shortcut for $res->header('content-length').
location
my $url = $res->location;
Shortcut for $res->header('location'). Useful for redirects.