NAME

Future::HTTP::Tiny - synchronous HTTP client with a Future interface

DESCRIPTION

This is the default backend. It is chosen if no supported event loop could be detected. It will execute the requests synchronously as they are made in ->http_request .

Whitelist / Blacklist

You can set up the whitelist and blacklist through the global accessors:

  # Allow access to localhost
  HTTP::Tiny::Paranoid->whitelisted_hosts([ 'localhost', '127.0.0.1' ]);

  # Deny access to localhost
  HTTP::Tiny::Paranoid->blacklisted_hosts([ 'localhost', '127.0.0.1' ]);

METHODS

Future::HTTP::Tiny->new()

    my $ua = Future::HTTP::Tiny->new();

Creates a new instance of the HTTP client.

$ua->http_get($url, %options)

    $ua->http_get('http://example.com/',
        headers => {
            'Accept' => 'text/json',
        },
    )->then(sub {
        my( $body, $headers ) = @_;
        ...
    });

Retrieves the URL and returns the body and headers, like the function in AnyEvent::HTTP.

$ua->http_head($url, %options)

    $ua->http_head('http://example.com/',
        headers => {
            'Accept' => 'text/json',
        },
    )->then(sub {
        my( $body, $headers ) = @_;
        ...
    });

Retrieves the header of the URL and returns the headers, like the function in AnyEvent::HTTP.

$ua->http_post($url, $body, %options)

    $ua->http_post('http://example.com/api',
        '{token:"my_json_token"}',
        headers => {
            'Accept' => 'text/json',
        },
    )->then(sub {
        my( $body, $headers ) = @_;
        ...
    });

Posts the content to the URL and returns the body and headers, like the function in AnyEvent::HTTP.

$ua->http_request($method, $url, %options)

    $ua->http_request('PUT' => 'http://example.com/api',
        headers => {
            'Accept' => 'text/json',
        },
        body    => '{token:"my_json_token"}',
    )->then(sub {
        my( $body, $headers ) = @_;
        ...
    });

Posts the content to the URL and returns the body and headers, like the function in AnyEvent::HTTP.

COMPATIBILITY

HTTP::Tiny is a good backend because it is distributed with many versions of Perl. The drawback is that not all versions of HTTP::Tiny support all features. The following features are unsupported on older versions of HTTP::Tiny:

->{URL}

HTTP::Tiny versions before 0.018 didn't tell about 30x redirections.

->{redirects}

HTTP::Tiny versions before 0.058 didn't record the chain of redirects.

SEE ALSO

Future

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-2019 by Max Maischein corion@cpan.org.

LICENSE

This module is released under the same terms as Perl itself.