API-Client
view release on metacpan or search on metacpan
NAME
API::Client
ABSTRACT
HTTP API Thin-Client Abstraction
SYNOPSIS
package main;
use API::Client;
my $client = API::Client->new(url => 'https://httpbin.org');
# $client->resource('post');
# $client->update(json => {...});
DESCRIPTION
This package provides an abstraction and method for rapidly developing
HTTP API clients. While this module can be used to interact with APIs
directly, API::Client was designed to be consumed (subclassed) by
higher-level purpose-specific API clients.
THIN CLIENT
The thin API client library is advantageous as it has complete API
coverage and can easily adapt to changes in the API with minimal
effort. As a thin-client superclass, this module does not map specific
HTTP requests to specific routines, nor does it provide parameter
validation, pagination, or other conventions found in typical API
client implementations; Instead, it simply provides a simple and
consistent mechanism for dynamically generating HTTP requests.
Additionally, this module has support for debugging and retrying API
calls as well as throwing exceptions when 4xx and 5xx server response
codes are returned.
INTEGRATES
This package integrates behaviors from:
Data::Object::Role::Buildable
Data::Object::Role::Stashable
Data::Object::Role::Throwable
LIBRARIES
This package uses type constraints from:
Types::Standard
SCENARIOS
This package supports the following scenarios:
building
# given: synopsis
my $resource = $client->resource('get');
# GET /get
my $get = $client->resource('get')->dispatch;
# HEAD /head
my $head = $client->resource('head')->dispatch(
method => 'head'
);
# PATCH /patch
my $patch = $client->resource('patch')->dispatch(
method => 'patch'
);
[$get, $head, $patch]
Building up an HTTP request is extremely easy, simply call the
"resource" to create a new object instance representing the API
endpoint you wish to issue a request against.
chaining
# given: synopsis
# https://httpbin.org/users
my $users = $client->resource('users');
( run in 1.247 second using v1.01-cache-2.11-cpan-39bf76dae61 )