Client REST

2 minute readReferenceExtensibilityDeveloper productivity

This class provides methods required to support a simple rest client for various HTTP interactions. It has been designed to be as closest as possible to HTTP::Request and LWP::UserAgent object methods.

The following is an example of its usage.

sub stepGetContent { my ($pluginObject) = @_; # retrieving context object my $context = $pluginObject->getContext(); # creating new FlowPDF::Client::REST object my $rest = $context->newRESTClient(); # creatung new HTTP::Request object using FlowPDF APIs my $request = $rest->newRequest(GET => 'http://electric-cloud.com'); # performing request and getting HTTP::Response object. my $response = $rest->doRequest($request); # printing response content print "Content: ", $response->decoded_content(); }

new($parameters)

Class Constructor. Creates new FlowPDF::Client::REST object.

To use FlowPDF::Client::REST with proxy provide a proxy parameters to constructor. They are:

  • url

    Address of the proxy to be used as http proxy.

  • username

    username for proxy authorization.

  • password

    password for proxy authorization.

  • debug

    Switch to enable debug. If set to True FlowPDF::Proxy will be enabled for debug as well.

Parameters

  • (Optional)(HASH ref) Parameter used to retrieve additional information from FlowPDF::Client::REST.

Returns

FlowPDF::Client::REST

Usage

my $rest = FlowPDF::Client::REST->new({ proxy => { url => 'http://squid:3128', username => 'user1', password => 'user2' } });

As can be seen above FlowPDF::Rest loads automatically to create a new instance of FlowPDF::Client::REST.

newRequest(@parameters)

Creates new HTTP::Request object.

This wrapper has been created to implement augmenations to components during request object creation.

For example, if FlowPDF::Client::Rest has been created with proxy support, it will return HTTP::Request object with applied proxy fields.

This method has the same interface and usage as HTTP::Request::new();

Parameters

HTTP::Request::new() parameters.

Returns

HTTP::Request

Usage

my $request = $rest->newRequest(GET => 'https://electric-cloud.com');

doRequest($httpRequest)

Performs HTTP request, using HTTP::Request object as parameter, leveraging the LWP::UserAgent::request() method.

Parameters

LWP::UserAgent::request() parameters

Returns

HTTP::Response

Usage

my $request = $rest->newRequest(GET => 'https://electric-cloud.com'); my $response = $rest->doRequest($request); print $response->decoded_content();

augmentUrlWithParams($url, $arguments)

Helper method, that provides a mechanism for adding query parameters to URL, with proper escaping.

Parameters

  • (Required)(String) Url that should be augmented with query parameters.

  • (Required)(HASH ref) hash of parameters to be escaped and added to the query string.

Returns

(String) Url with added query parameters.

Usage

my $url = 'http://localhost:8080'; $url = $rest->augmentUrlWithParams($url, {one=>'two'}); # url = http://localhost:8080?one=two