NAME

WWW::Hetzner::Role::HTTP - HTTP client role for Hetzner API clients

VERSION

version 0.001

SYNOPSIS

package WWW::Hetzner::Cloud;
use Moo;

has token => ( is => 'ro' );
has base_url => ( is => 'ro', default => 'https://api.hetzner.cloud/v1' );

with 'WWW::Hetzner::Role::HTTP';

DESCRIPTION

This role provides HTTP methods (GET, POST, PUT, DELETE) for Hetzner API clients. It handles JSON encoding/decoding, authentication, and error handling.

Uses Log::Any for logging HTTP requests and responses.

NAME

WWW::Hetzner::Role::HTTP - HTTP client role for Hetzner API clients

REQUIRED ATTRIBUTES

Classes consuming this role must provide:

  • token - API authentication token

  • base_url - Base URL for the API

CUSTOMIZATION

_set_auth

Override this method to change authentication. Default is Bearer token:

sub _set_auth {
    my ($self, $request) = @_;
    $request->header('Authorization' => 'Bearer ' . $self->token);
}

For Basic Auth (e.g. Robot API):

sub _set_auth {
    my ($self, $request) = @_;
    $request->authorization_basic($self->user, $self->password);
}

PROVIDED METHODS

get

my $data = $self->get('/path', params => { key => 'value' });

post

my $data = $self->post('/path', { key => 'value' });

put

my $data = $self->put('/path', { key => 'value' });

delete

my $data = $self->delete('/path');

SEE ALSO

WWW::Hetzner::Cloud, Log::Any

SUPPORT

Source Code

The code is open to the world, and available for you to hack on. Please feel free to browse it and play with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull from your repository :)

https://github.com/Getty/p5-www-hetzner

git clone https://github.com/Getty/p5-www-hetzner.git

AUTHOR

Torsten Raudssus <torsten@raudssus.de>

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.