IO::Lambda::HTTP::Server - simple httpd server
The module exports a single function http_server that accepts a callback and a socket, with optional parameters. The callback accepts a HTTP::Request object, and is expected to return either a HTTP::Response object or a lambda that in turn returns a a HTTP::Response object.
http_server
HTTP::Request
HTTP::Response
use HTTP::Request; use IO::Lambda qw(:all); use IO::Lambda::HTTP qw(http_request); use IO::Lambda::HTTP::Server; my $server = http_server { my $req = shift; if ( $req->uri =~ /weather/) { context( HTTP::Request-> new( GET => "http://www.google.com/?q=weather")); return &http_request; } else { return HTTP::Response->new(200, 'OK', ['Content-Type' => 'text/plain'], "hello world"); } } "localhost:80"; $server->start; # runs in 'background' now
Creates lambda that listens on $socket, that is either a IO::Socket::INET object or a string such as "localhost" or "127.0.0.1:9999".
$socket
IO::Socket::INET
"localhost"
"127.0.0.1:9999"
The callback accepts a HTTP::Request object, and is expected to return either a HTTP::Response object or a lambda that in turn returns a a HTTP::Response object.
Options:
Connection timeout or a deadline.
Enter a graceful shutdown mode - stop accepting new connections, handle the running ones, and stop after all connections are served.
IO::Lambda, HTTP::Request, HTTP::Response
Dmitry Karasik, <dmitry@karasik.eu.org>.
To install IO::Lambda, copy and paste the appropriate command in to your terminal.
cpanm
cpanm IO::Lambda
CPAN shell
perl -MCPAN -e shell install IO::Lambda
For more information on module installation, please visit the detailed CPAN module installation guide.