NAME
HTTP::API::Core::Response - HTTP API response object
CONSTRUCTION
new
my $response = HTTP::API::Core::Response->new(
status => 200,
headers => { 'Content-Type' => 'application/json' },
content => '{}',
);
Creates a response object. status must be an HTTP status in the 100-599 range. headers is a hash reference with scalar, array-of-scalar or undefined values; reason, content, method, url and elapsed are optional scalar metadata. Missing content becomes an empty string. Header names are normalized case-insensitively.
RESPONSE BODY
content
Returns the raw response body exactly as supplied by the transport.
text
An alias for content. No charset transcoding is performed.
has_content
Returns true when the raw response body has non-zero length.
json
Decodes the response body as JSON. An empty or whitespace-only body returns undef. JSON decoding is explicit: json attempts to decode regardless of the response Content-Type header, and throws a structured decode error when non-empty content is not valid JSON.
CONTENT TYPE
content_type
Returns the lower-cased media type from Content-Type, excluding parameters such as charset. Returns undef when the header is absent.
is_json
Returns true for application/json and structured syntax suffix media types ending in +json, such as application/problem+json.
METADATA
status, reason, headers, header, method, url
Provide response status and request metadata. headers returns a defensive copy, including copies of array references for repeated headers such as Set-Cookie. header($name) returns a scalar for a single value or identical repeated values; conflicting repeated values return undef. Case-insensitively duplicated header names with matching values are preserved; conflicting values become undef rather than being chosen arbitrarily.
is_success
Returns true for HTTP status codes 200 through 299, and false otherwise.
rate_limit
Returns an HTTP::API::Core::RateLimit object derived from the response headers. Ambiguous scalar header values are not used to infer quota or retry delay.
elapsed
Returns transport elapsed time when available.
request_id
Returns the first non-empty X-Request-Id, Request-Id, or X-Correlation-Id value.