NAME

Kubernetes::REST::Role::IO - Interface role for HTTP backends

VERSION

version 1.106

SYNOPSIS

package My::AsyncIO;
use Moo;
with 'Kubernetes::REST::Role::IO';

sub call {
    my ($self, $req) = @_;
    # Execute HTTP request, return Kubernetes::REST::HTTPResponse
    ...
}

sub call_streaming {
    my ($self, $req, $data_callback) = @_;
    # Execute HTTP request with streaming callback
    ...
}

# Optional: full-duplex transport (WebSocket/SPDY)
sub call_duplex {
    my ($self, $req, %callbacks) = @_;
    ...
}

DESCRIPTION

This role defines the interface that HTTP backends must implement. Kubernetes::REST delegates all HTTP communication through this interface, making it possible to swap out the transport layer.

The default backend is Kubernetes::REST::LWPIO (using LWP::UserAgent). An alternative Kubernetes::REST::HTTPTinyIO (using HTTP::Tiny) is provided. To use an async event loop, implement this role with e.g. Net::Async::HTTP.

Encoding contract

Request and response bodies are bytes, never character strings.

A backend receives $req->content already UTF-8 encoded and must put it on the wire unchanged. It must hand back $res->content - and every streaming chunk - as the bytes it received, undoing Content-Encoding (gzip) but not the charset. Kubernetes::REST decodes UTF-8 itself, together with IO::K8s, so a backend that decodes on its own causes silent double decoding (mojibake) on any non-ASCII value.

With LWP::UserAgent that means $res->decoded_content(charset => 'none') rather than $res->decoded_content.

call

my $response = $io->call($req);

Required. Execute an HTTP request. Receives a Kubernetes::REST::HTTPRequest with method, url, headers, and optionally content already set.

Must return a Kubernetes::REST::HTTPResponse with status and content, the latter as bytes - see "Encoding contract".

call_streaming

my $response = $io->call_streaming($req, $data_callback);

Required. Execute an HTTP request with streaming response. The $data_callback is called with each chunk of data as it arrives: $data_callback->($chunk). Chunks are bytes - see "Encoding contract".

Must return a Kubernetes::REST::HTTPResponse when the stream ends.

supports_duplex

if ($io->supports_duplex) {
    ...
}

Optional capability probe for full-duplex protocols used by Kubernetes subresources such as pod port-forward and exec/attach streams.

Returns true if the backend implements call_duplex, false otherwise.

SEE ALSO

SUPPORT

Issues

Please report bugs and feature requests on GitHub at https://github.com/pplu/kubernetes-rest/issues.

IRC

Join #kubernetes on irc.perl.org or message Getty directly.

CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

AUTHORS

  • Torsten Raudssus <torsten@raudssus.de>

  • Jose Luis Martinez Torres <jlmartin@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2019-2026 by Jose Luis Martinez Torres <jlmartin@cpan.org>.

This is free software, licensed under:

The Apache License, Version 2.0, January 2004