NAME
Open::API::Client - a spec driven HTTP client using Fetch
SYNOPSIS
my $client = Open::API::Client->new(
spec => 'openapi.json', # or api => $open_api
base_url => 'http://127.0.0.1:3000',
);
my $res = $client->call('getPet', petId => 42)->get;
# { status => 200, headers => {...}, data => { id => 42, ... } }
# operationId sugar (same as call):
$res = $client->getPet(petId => 42)->get;
DESCRIPTION
Builds requests from the same compiled OpenAPI 3.1 document the server side uses: parameters are validated client-side through the compiled JSON::Schema::Fast handles BEFORE any I/O (bad input croaks), the URL, query, headers, cookies and JSON body are assembled in C, and the request is fired through Fetch's C ABI. Every call returns a Fetch::Future: get awaits it synchronously, or pass loop => at construction to share an event loop and run calls concurrently.
The future resolves to a hashref: status, headers (lowercased names), data (JSON-decoded body when the response is application/json, raw bytes otherwise), and on failure error (with status 0 for transport errors). With validate => 1, a response that does not match the operation's response schema gets error and errors set.
CONSTRUCTOR
Open::API::Client->new(%opts);
api (an Open::API) or spec (anything "new" in Open::API accepts) is required, as is base_url. validate (default 0) checks response bodies against the spec. All other options (timeout, tls_verify, pool_size, loop, ...) are passed to Fetch's constructor on first use.
METHODS
call
my $future = $client->call($operationId, %params);
Flat %params are matched to the operation's declared parameters by name (body is the request body). Croaks before any I/O when a required parameter is missing or a value fails its schema.
api
The underlying Open::API object.
AUTHOR
LNATION <email@lnation.org>
LICENSE AND COPYRIGHT
This software is Copyright (c) 2026 by LNATION <email@lnation.org>.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)