SYNOPSIS

package MyDockerClient;
use Moo;

has host => (is => 'ro', required => 1);
has api_version => (is => 'ro');

with 'WWW::Docker::Role::HTTP';

# Now use get, post, put, delete_request methods
my $data = $self->get('/containers/json');

DESCRIPTION

This role provides HTTP transport for the Docker Engine API. It implements HTTP/1.1 communication over Unix sockets and TCP sockets without depending on heavy HTTP client libraries like LWP.

Features:

  • Unix socket transport (unix://...)

  • TCP socket transport (tcp://host:port)

  • HTTP/1.1 chunked transfer encoding

  • Automatic JSON encoding/decoding

  • Request/response logging via Log::Any

  • Automatic connection management

Consuming classes must provide host and api_version attributes.

my $data = $client->get($path, %opts);

Perform HTTP GET request. Returns decoded JSON or raw response body.

Options: params (hashref of query parameters).

$client->stream_get($path, params => \%params, callback => sub {
    my ($event) = @_;
    # $event is a decoded hashref for each NDJSON line
});

Perform a streaming HTTP GET request, reading the response body incrementally. The callback option is required and is invoked once per decoded JSON object as they arrive from the socket. This is suitable for long-lived Docker endpoints such as /events that send an unbounded NDJSON stream.

Options: params (hashref of query parameters), callback (required CodeRef).

my $data = $client->post($path, $body, %opts);

Perform HTTP POST request. $body is automatically JSON-encoded if provided.

Options: params (hashref of query parameters).

my $data = $client->put($path, $body, %opts);

Perform HTTP PUT request. $body is automatically JSON-encoded if provided.

Options: params (hashref of query parameters).

my $data = $client->delete_request($path, %opts);

Perform HTTP DELETE request.

Options: params (hashref of query parameters).

6 POD Errors

The following errors were encountered while parsing the POD:

Around line 274:

Unknown directive: =method

Around line 380:

Unknown directive: =method

Around line 402:

Unknown directive: =method

Around line 418:

Unknown directive: =method

Around line 433:

Unknown directive: =method

Around line 443:

Unknown directive: =seealso