-
-
13 Jun 2020 20:08:21 UTC
- Distribution: Future-HTTP
- Module version: 0.14
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Repository
- Issues (0)
- Testers (2 / 0 / 0)
- Kwalitee
Bus factor: 1- 35.17% Coverage
- License: perl_5
- Perl: v5.6.0
- Activity
24 month- Tools
- Download (23.68KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
NAME
Future::HTTP - provide the most appropriate HTTP client with a Future API
SYNOPSIS
my $ua = Future::HTTP->new(); my $res = $ua->http_get('http://www.nethype.de/')->then(sub { my( $body, $data ) = @_; # ... handle the response return $body })->get();
This module is a wrapper combining Future with the API provided by AnyEvent::HTTP. The backend used for the HTTP protocols depends on whether one of the event loops is loaded.
Supported event loops
Currently, the following backends are supported:
Support is planned for LWP::UserAgent and POE but has not materialized yet.
METHODS
Future::HTTP->new()
my $ua = Future::HTTP->new();
Creates a new instance of the HTTP client.
$ua->is_async()
Returns true if the selected backend is asynchronous, false if it is synchronous.
$ua->http_get($url, %options)
my $res = $ua->http_get('http://example.com/', headers => { 'Accept' => 'text/json', }, )->then(sub { my( $body, $headers ) = @_; # ... handle the response })->get;
Retrieves the URL and returns the body and headers, like the function in AnyEvent::HTTP.
$ua->http_head($url, %options)
my $res = $ua->http_head('http://example.com/', headers => { 'Accept' => 'text/json', }, )->then(sub { my( $body, $headers ) = @_; ... })->get;
Retrieves the header of the URL and returns the headers, like the function in AnyEvent::HTTP.
$ua->http_post($url, $body, %options)
my $res = $ua->http_post('http://example.com/api', '{token:"my_json_token"}', headers => { 'Accept' => 'text/json', }, )->then(sub { my( $body, $headers ) = @_; ... })->get;
Posts the content to the URL and returns the body and headers, like the function in AnyEvent::HTTP.
$ua->http_request($method, $url, %options)
my $res = $ua->http_request('PUT' => 'http://example.com/api', headers => { 'Accept' => 'text/json', }, body => '{token:"my_json_token"}', )->then(sub { my( $body, $headers ) = @_; ... })->get;
Posts the content to the URL and returns the body and headers, like the function in AnyEvent::HTTP.
SEE ALSO
AnyEvent::HTTP for the details of the API
REPOSITORY
The public repository of this module is https://github.com/Corion/future-http.
SUPPORT
The public support forum of this module is https://perlmonks.org/.
BUG TRACKER
Please report bugs in this module via the RT CPAN bug queue at https://rt.cpan.org/Public/Dist/Display.html?Name=Future-HTTP or via mail to future-http-Bugs@rt.cpan.org.
AUTHOR
Max Maischein
corion@cpan.org
COPYRIGHT (c)
Copyright 2016-2020 by Max Maischein
corion@cpan.org
.LICENSE
This module is released under the same terms as Perl itself.
Module Install Instructions
To install Future::HTTP, copy and paste the appropriate command in to your terminal.
cpanm Future::HTTP
perl -MCPAN -e shell install Future::HTTP
For more information on module installation, please visit the detailed CPAN module installation guide.