NAME

MooX::Role::REST - Simple HTTP client for JSON-REST as a Moo::Role

ATTRIBUTES

These are inherited from MooX::Role::HTTP::Tiny:

base_uri [Required]

The base URI for the REST-API.

ua [Lazy]

Instantiated HTTP::Tiny instance. Will be created once needed.

ua_options [Optional]

The contents of this HashRef will be passed to the constructor for HTTP::Tiny (in case of lazy construction).

SYNOPSIS

package My::Client;
use Moo;
with qw< MooX::Role::REST >;
1;

package My::API;
use Moo;
use Types::Standard qw< InstanceOf >;
has client => (
    is       => 'ro',
    isa      => InstanceOf(['My::Client']),
    handles  => [qw< call >],
    required => 1,
);
sub search_release {
    my $self = shift;
    my ($query) = @_;
    $query =~ s{ :: }{-}xg;
    return $self->call(GET => 'release/_search', { q => $query });
}
1;

package main;
use warnings;
use v5.14.0; # strict + feature
use Data::Dumper;

# Show request/response on STDERR
{ no warnings 'once'; $MooX::Role::REST::DEBUG = 1; }

my $client = My::Client->new(base_uri => 'https://fastapi.metacpan.org/v1/');
my $api = My::API->new(client => $client);

say Dumper($api->search_release('MooX::Params::CompiledValidators'));

DESCRIPTION

Helper role to implement a simple REST client with JSON.

call

Mandatory method that implements the actual HTTP stuff.

ValidationTemplates

Validation templates for the call() method.

http_method => Enum< GET POST PUT DELETE PATCH >
call_path => Str
call_data => Maybe[HashRef]

COPYRIGHT

© MMXXIII - Abe Timmerman <abeltje@cpan.org>

LICENSE

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

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.