++ed by:

1 PAUSE user

Paul Evans


Net::Async::HTTP::Server - serve HTTP with IO::Async


 use Net::Async::HTTP::Server;
 use IO::Async::Loop;

 use HTTP::Response;

 my $loop = IO::Async::Loop->new();

 my $httpserver = Net::Async::HTTP::Server->new(
    on_request => sub {
       my $self = shift;
       my ( $req ) = @_;

       my $response = HTTP::Response->new( 200 );
       $response->add_content( "Hello, world!\n" );
       $response->content_type( "text/plain" );
       $response->content_length( length $response->content );

       $req->respond( $response );

 $loop->add( $httpserver );

    addr => { family => "inet6", socktype => "stream", port => 8080 },
    on_listen_error => sub { die "Cannot listen - $_[-1]\n" },



This module allows a program to respond asynchronously to HTTP requests, as part of a program based on IO::Async. An object in this class listens on a single port and invokes the on_request callback or subclass method whenever an HTTP request is received, allowing the program to respond to it.

For accepting HTTP connections via PSGI and Plack, see also Plack::Handler::Net::Async::HTTP::Server.


on_request $req

Invoked when a new HTTP request is received. It will be passed a Net::Async::HTTP::Server::Request object.


  • Don't use HTTP::Message objects as underlying implementation

  • Consider how to do streaming request inbound

  • Lots more testing


Paul Evans <leonerd@leonerd.org.uk>