Skip to content
Interfaces and default implementations for rolling your own http client and/or components
Perl 6
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib/Net/HTTP Add appropriate error message for unexpected EOF Mar 26, 2019
.travis.yml Use -I. instead of -Ilib for ci tests Aug 22, 2017



Interfaces and default implementations for rolling your own http client and/or components


use Net::HTTP::GET;
my %header   = :Connection<keep-alive>;
my $response = Net::HTTP::GET("", :%header);
say $response.content;

use Net::HTTP::POST;
my $body     ="a=b&c=d&f=".ords);
my $response = Net::HTTP::POST("", :$body);
say $response.content;


Connection caching/keep-alive, thread safety (?), highly interfaceable. Loosely modeled on the golang http library with the goal of having a strong separation of components to allow easy interchangability.

Coming soon

Cookies, multipart posting

How do I...?

Use a proxy

Simply add a proxy method to your client or transport object. For instance, to simply return a url from a string you could do:

my $transport =;
$transport does role { 
    method proxy { ::('Net::HTTP::URL').new("") }

But you could also implement rotating proxies, proxy from $*ENV, etc

Client Implementations


my $response = Net::HTTP::GET("");

Simple access to the http GET client api.


my $body ="a=1&b=2".ords);
my $response = Net::HTTP::POST("", :$body);

Simple access to the http POST client api (Still lacking anything beyond basic functionality)


my $url =$abs-url);
my $req =$url, :method<GET>, :User-Agent<perl6-net-http>);
my $transport =;
my $response  = $transport.round-trip($req);

A high level round-robin implementation that attempts connection caching and is thread safe. For a user-agent level implementation that handles cookies, redirects, auth, etc then use a Net::HTTP::Client. Can provide an alternative Response object as an argument.

> use HTTP::SomethingElse::Response;
> my \ALTRESPONSE = HTTP::SomethingElse::Response;
> my $response    = $transport.round-trip($req, ALTRESPONSE);



Highest level of http client implementation.

Interface Default Implementations

Most Net::HTTP components can be swapped out for generic alternatives. Net::HTTP provides a set of interfaces (see: Net::HTTP::Interfaces) and the other included classes in Net::HTTP can be viewed as default implementations.


my $url ="");

Create a url object to provide an api to the url parts, such as scheme, host, and port.

> say ~$url
> say $;


my $url     ="");
my $request =$url, :method<GET>, header => :Host<>);

Create a Request object which provides an api to generating an over-the-wire or human readable representation of an http request. .raw gives a binary representation, and .Str gives a utf8 encoded version.

> my $socket =<>, :port(80));
> $socket.write($request.raw)


my $response-from-args =$status-line, :%header, :$body);
my $response-from-buf  =$response-as-buf);

Creates a Response object that provides an api to parsing an http response. It can be created with named arguments representing the http message parts, or it can be given a raw Blob.

> my $data = andthen while $socket.recv(:bin) -> d { $data ~= $d }
> my $response =$data)


my $url     ="");
my $request =$url, :method<GET>, header => :Host<>);
my $socket  =$request);

A role for providing access to scheme appropriate socket connections.

You can’t perform that action at this time.