NAME

   WebService::BaseClientRole

VERSION

   version 0.0004

SYNOPSIS

       # Easily create a web service client:
       # FILE: lib/WebService/Foo.pm

       package WebService::Foo;
       use Moo;
       with 'WebService::BaseClientRole';

       has auth_token => ( is => 'ro', required => 1 );
       has '+base_url' => ( default => 'https://foo.com/v1' );

       sub BUILD {
           my ($self) = @_;
           $self->ua->default_header('X-Auth-Token' => $self->auth_token);
       }

       sub get_widgets {
           my ($self) = @_;
           return $self->get("/widgets");
       }

       sub get_widget {
           my ($self, $id) = @_;
           return $self->get("/widgets/$id");
       }

       sub create_widget {
           my ($self, $widget_data) = @_;
           return $self->post("/widgets", $widget_data);
       }

       1;

       # Example usage
       # FILE: foo.pl

       my $client = WebService::Foo->new(
           auth_token => 'abc',
           logger     => Log::Tiny->new('/tmp/foo.log'), # optional
           timeout    => 10, # optional, defaults to 10
           retries    => 0,  # optional, defaults to 0
       );
       $client->create_widget({ color => 'blue' });

DESCRIPTION

   This module is a generic base role for quickly and easily creating web
   service clients. Every time I created a web service client, I noticed
   that I kept rewriting the same boilerplate code independent of the web
   service. This module does the boring boilerplate for you so you can
   just focus on the fun part - writing the web service specific code.

SEE ALSO

     * Net::HTTP::API

     * Role::REST::Client

AUTHOR

   Naveed Massjouni <[email protected]>

COPYRIGHT AND LICENSE

   This software is copyright (c) 2014 by Naveed Massjouni.

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