NAME
HTTP::API::Client - Small foundation for JSON HTTP API clients
SYNOPSIS
use HTTP::API::Client;
my $api = HTTP::API::Client->new(
base_url => 'https://api.example.com',
headers => { Authorization => "Bearer $token" },
timeout => 10,
);
my $response = $api->get('/users');
my $users = $response->json;
my $created = $api->post('/users', json => { name => 'Alice' });
DESCRIPTION
HTTP::API::Client is a deliberately small base layer for building HTTP API clients. Version 0.01 provides base URL handling, default headers, JSON request encoding, JSON response decoding, timeout configuration, and structured errors.
It uses HTTP::Tiny and JSON::PP, both available with modern Perl.
METHODS
new
my $api = HTTP::API::Client->new(
base_url => 'https://api.example.com',
headers => { ... },
timeout => 10,
);
base_url is required. headers and timeout are optional.
get, post, put, patch, delete
Convenience methods around request.
request
my $response = $api->request('POST', '/items', json => { ... });
Pass json to encode a Perl value as JSON, or content to send raw content. Per-request headers override default headers.
Non-2xx responses throw HTTP::API::Client::Error.
ERROR HANDLING
Errors expose stable fields such as category, status, method, url, retryable, retry_after, and request_id. Exact error message wording is not intended as a machine-readable API.
LICENSE
This library is free software; you may redistribute it and/or modify it under the same terms as Perl itself.