Net::Async::Webservice::Common::WithRequestWrapper - helper methods to perform HTTP request
version 0.01_4
package My::WS::Client { use Moo; with 'Net::Async::Webservice::Common::WithUserAgent'; with 'Net::Async::Webservice::Common::WithRequestWrapper'; } my $loop = IO::Async::Loop->new; my $c = My::WS::Client->new({loop=>$loop}); $c->post('https://api.webservice.whatever/',$content)->then(sub{ my ($response_body) = @_; say "Got <$response_body>"; return Future->wrap(); })->get;
This role provides a few methods to perform HTTP requests via a user_agent attribute / method (which is required, and could be provided by Net::Async::Webservice::Common::WithUserAgent or any other means).
user_agent
Failures (both during connection, and as signaled by the HTTP response codes) are wrapped in Net::Async::Webservice::Common::Exception::HTTPError and returned as failed futures. On success, the future yields the decoded content of the response.
ssl_options
Optional hashref, its contents will be passed to user_agent's do_request method.
do_request
request
$c->request($http_request) ==> $decoded_content
Performs the given request via the user_agent, with fail_on_error set; if the request succeeds, the returned future will yield the decoded content of the response. If the request fails, the future will fail with a two-element failure: a Net::Async::Webservice::Common::Exception::HTTPError and the string 'webservice'.
fail_on_error
'webservice'
post
$c->post($url,$body) ==> $decoded_content
Shortcut to submit a very basic POST request. The $body will be UTF-8 encoded, no headers are set. Uses "request" to perform the actual request.
$body
get
$c->get($url) ==> $decoded_content
Shortcut to submit a very basic GET request. No headers are set. Uses "request" to perform the actual request.
Gianni Ceccarelli <gianni.ceccarelli@net-a-porter.com>
This software is copyright (c) 2014 by Net-a-porter.com.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Net::Async::Webservice::Common, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::Async::Webservice::Common
CPAN shell
perl -MCPAN -e shell install Net::Async::Webservice::Common
For more information on module installation, please visit the detailed CPAN module installation guide.