-
-
30 Jun 2019 08:19:09 UTC
- Distribution: IO-Lambda
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Repository
- Issues (0)
- Testers (562 / 103 / 0)
- Kwalitee
Bus factor: 1- % Coverage
- License: perl_5
- Activity
24 month- Tools
- Download (90.24KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
- Dependencies
- LWP
- Net::DNS
- Scalar::Util
- Storable
- Sub::Name
- Time::HiRes
- URI
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
IO::Lambda::HTTP::Server - simple httpd server
DESCRIPTION
The module exports a single function
http_server
that accepts a callback and a socket, with optional parameters. The callback accepts aHTTP::Request
object, and is expected to return either aHTTP::Response
object or a lambda that in turn returns a aHTTP::Response
object.SYNOPSIS
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
API
- http_server &callback, $socket, [ %options ]
-
Creates lambda that listens on
$socket
, that is either aIO::Socket::INET
object or a string such as"localhost"
or"127.0.0.1:9999"
.The callback accepts a
HTTP::Request
object, and is expected to return either aHTTP::Response
object or a lambda that in turn returns a aHTTP::Response
object.Options:
- shutdown
-
Enter a graceful shutdown mode - stop accepting new connections, handle the running ones, and stop after all connections are served.
SEE ALSO
IO::Lambda, HTTP::Request, HTTP::Response
AUTHOR
Dmitry Karasik, <dmitry@karasik.eu.org>.
Module Install Instructions
To install IO::Lambda, copy and paste the appropriate command in to your terminal.
cpanm IO::Lambda
perl -MCPAN -e shell install IO::Lambda
For more information on module installation, please visit the detailed CPAN module installation guide.