NAME
RestAPI - a base module to interact with a REST API interface
VERSION
Version 0.09
SYNOPSIS
use RestAPI;
# a REST GET request
my $client = RestAPI->new(
basicAuth => 1,
realm => "Some Realm",
ssl_opts => { verify_hostname => 0 },
username => "foo",
password => "bar",
timeout => 10, # in secs
scheme => 'https', # if missing it is assumed comprised in the server or in the query
server => '...',
query => '...', # (maybe fixed) request part
path => '...', # added alongside the request
q_params => { foo => bar },
headers => { k => 'v' },
http_verb => 'GET', # any http verb...
encoding => 'application/xml' # or whatever...
);
# a REST POST request
my $client = RestAPI->new(
basicAuth => 1,
realm => "Some Realm",
username => "foo",
password => "bar",
scheme => 'https',
timeout => 10, # in secs
server => '...',
query => '...',
path => '...',
q_params => { foo => bar },
http_verb => 'POST',
payload => '...',
encoding => 'application/xml'
);
# a REST UPDATE request
my $client = RestAPI->new(
basicAuth => 1,
realm => "Some Realm",
username => "foo",
password => "bar",
scheme => 'https',
timeout => 10, # in secs
server => '...',
query => '...',
path => '...',
q_params => { foo => bar },
http_verb => 'PUT',
payload => '...',
encoding => 'application/xml'
);
# a REST DELETE request
my $client = RestAPI->new(
basicAuth => 1,
realm => "Some Realm",
username => "foo",
password => "bar",
scheme => 'https',
timeout => 10, # in secs
server => '...',
query => '...',
path => '...',
q_params => { foo => bar },
http_verb => 'DELETE',
encoding => 'application/xml'
);
try {
my $response_data = $client->do();
# $self->response is the HTTP::Response object
# you get back from your request...
my %response_headers = $client->response->flatten();
} catch {
die "Error performing request, status line: $!\n";
}
my $raw_response = $client->raw(); # the raw response.
EXPORT
None
AUTHOR
Marco Masetti, <marco.masetti at sky.uk>
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc RestAPI
LICENSE AND COPYRIGHT
Copyright 2017 Marco Masetti.
This program is free software; you can redistribute it and/or modify it under the terms of Perl itself.