Giter Club home page Giter Club logo

future-http's Introduction

Travis Build Status AppVeyor Build Status

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

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 [email protected].

AUTHOR

Max Maischein [email protected]

COPYRIGHT (c)

Copyright 2016-2024 by Max Maischein [email protected].

LICENSE

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

future-http's People

Contributors

corion avatar haukex avatar haarg avatar

Stargazers

Alexey Ugnichev avatar Sanko Robinson avatar  avatar

Watchers

 avatar James Cloos avatar  avatar  avatar

Forkers

haukex sanko haarg

future-http's Issues

tests hangs smoke tests

Discovered during execution of smoke tests with CPAN::Reporter::Smoker running on OpenBSD 6.3 with perl 5.28.0 installed with perlbrew

Tests hang after t/00-load.t, with the following output:

t/00-load.t ..................... ok
# Version of AnyEvent::HTTP: 2.23
Use of uninitialized value $url in scalar chomp at <long path>/lib/site_perl/5.28.0/Test/HTTP/LocalServer.pm line 173.

Tests only end upon receiving SIGINT (CRLT+C)

status codes for failure

if( $headers->{Status} =~ /^2../ ) { return Future->done($body, $headers); } else { return Future->fail($body, $headers); }

Are redirects(301 and 302) suppose to be registered as a fail?

It might even make sense to allow overloading of that as some web apis use their own status codes to mean different things.

Tests expect an exact number of warnings

Unfortunately I learned the hard way (e.g. haukex/IPC-Run3-Shell#5) that tests should not expect an exact number of warnings, but t/01-mojo.t does. The issue shows up e.g. here: https://travis-ci.org/Corion/future-http/jobs/452344391. My experience has been to either test for the presence of specific warnings that one's own code produces, or to test for the absence of specific warnings that should not happen.

I could provide a patch - which warnings is t/01-mojo.t looking for specifically? Edit: Oh, I see: #2, more specifically mojolicious/mojo#1221. Since it seems the issue was fixed in 555906a, maybe it'd be best to remove the "no warnings" test, or make it specific to Use of uninitialized value $chunk in concatenation? Edit 2: Possible patch provided in #7.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.