Future::HTTP(3pm)

πŸ“¦
version 0.17 Β· 4 versions
, in ubuntu resolute, ubuntu stonking

πŸ’– Future::HTTP πŸ’–

okay bestie, so this is Future::HTTP β€” from the User Contributed Perl Documentation crew (that's the manual it lives in, iykyk) β€” and it's literally the ✨most appropriate✨ HTTP client with a Future API. no cap.


🌸 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();

So here's the tea πŸ«–: this module is a wrapper that smashes Future together with the API that AnyEvent::HTTP gives you. and which backend actually ends up handling your HTTP protocols? that depends entirely on whether one of the event loops is loaded. it picks for you. main character energy, honestly. πŸ‘‘


πŸ¦‹ Supported event loops πŸ¦‹

as of right now, these are the backends that get support:

  • HTTP::Tiny
  • HTTP::Tiny::Paranoid
  • Mojolicious
  • AnyEvent
  • IO::Async

and support is planned for LWP::UserAgent and POE, but it has not materialized yet 😭 (they're on the vision board, not in the codebase, fr fr).


πŸŽ€ METHODS πŸŽ€

πŸ’… Future::HTTP->new()

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

Creates a brand new instance of the HTTP client. fresh out the box, obsessed. ✨


πŸ’œ $ua->is_async()

Returns true if the backend that got selected is asynchronous, and false if it's synchronous. tiny little vibe check for your backend. 🌈


πŸ“ $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 hands you back the body and the headers, exactly like the function in AnyEvent::HTTP does it. 🫢


🧚 $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. yes, just like that. no notes. πŸ’–


⭐ $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. slay. πŸ”₯


🌸 $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. (yes, the description for this one is word-for-word the same as the POST one β€” the docs did that, not me, and I'm keeping it πŸ’€) πŸ™ˆ


πŸ‘‘ 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>.

go star it, it's giving community support πŸ’œ


🫢 SUPPORT 🫢

The public support forum of this module is <https://perlmonks.org/>. the monks are lovely, ask them anything, fr fr.


πŸ’€ 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.

(not me begging you to actually report the bugs instead of just suffering in silence 😭 do it for us.)


✨ AUTHOR ✨

Max Maischein "corion@cpan.org"


Copyright 2016-2024 by Max Maischein "corion@cpan.org".


🌟 LICENSE 🌟

This module is released under the same terms as Perl itself. iconic behavior, truly. πŸ‘‘


and that's the whole page bestie, mwah πŸ’‹ β€” this lil manual page came to you from perl v5.40.1, dated 2026-01-14, filed under Future::HTTP(3pm) in the User Contributed Perl Documentation. go write something async, ily πŸ¦‹βœ¨

πŸ“¦ where this page comes from