2 AnyEvent::HTTPD - A simple lightweight event based web (application)
11 my $httpd = AnyEvent::HTTPD->new (port => 9090);
15 my ($httpd, $req) = @_;
17 $req->o ("<html><body><h1>Hello World!</h1>");
18 $req->o ("<a href=\"/test\">another test page</a>");
19 $req->o ("</body></html>");
23 my ($httpd, $req) = @_;
25 $req->o ("<html><body><h1>Test page</h1>");
26 $req->o ("<a href=\"/\">Back to the main page</a>");
27 $req->o ("</body></html>");
33 This module provides a simple HTTPD for serving simple web application
34 interfaces. It's completly event based and independend from any event
35 loop by using the AnyEvent module.
37 It's HTTP implementation is a bit hacky, so before using this module
38 make sure it works for you and the expected deployment. Feel free to
39 improve the HTTP support and send in patches!
41 The documentation is currently only the source code, but next versions
42 of this module will be better documented hopefully. See also the
43 "samples/" directory in the AnyEvent::HTTPD distribution for basic
46 AnyEvent::HTTPD even comes with some basic AJAX framework/helper.
49 * support for GET and POST requests
51 * processing of "x-www-form-urlencoded" and "multipart/form-data"
52 encoded form parameters
54 * ajax helper and javascript output functions in
55 AnyEvent::HTTPD::Appgets
57 * support for chunked encoding output to the HTTP client
60 The AnyEvent::HTTPD class inherits directly from
61 AnyEvent::HTTPD::HTTPServer which inherits the event callback interface
64 Event callbacks can be registered via the Object::Event API (see the
65 documentation of Object::Event for details).
67 For a list of available events see below in the *EVENTS* section.
70 This is the constructor for a AnyEvent::HTTPD object. The %args hash
71 may contain one of these key/value pairs:
74 The TCP port the HTTP server will listen on.
77 Every request goes to a specific URL. After a (GET or POST) request is
78 received the URL is split at the '/' characters and joined again with
79 '_' characters. After that the event with the name of the converted URL
80 is invoked, this means that if you get a request to the url '/test/bla'
81 the even "_test_bla" is emitted, you can register a callback for that
86 my ($httpd, $req) = @_;
88 $req->respond ([200, 'ok', { 'Content-Type' => 'text/html' }, '<h1>Test</h1>' }]);
92 The first argument to such a callback is always the AnyEvent::HTTPD
93 object itself. The second argument ($req) is the
94 AnyEvent::HTTPD::Request object for this request. It can be used to get
95 the (possible) form parameters for this request or the transmitted
96 content and respond to the request.
98 Also every request also emits the "request" event, with the same
99 arguments and semantics, you can use this to implement your own request
103 Any response from the HTTP server will have "Cache-Control" set to
104 "max-age=0" and also the "Expires" header set to the "Date" header.
105 Meaning: Caching is disabled.
107 If you need caching or would like to have it you can send me a mail or
108 even better: a patch :)
111 Robin Redeker, "<elmex at ta-sa.org>"
114 Please report any bugs or feature requests to "bug-bs-httpd at
115 rt.cpan.org", or through the web interface at
116 <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=AnyEvent-HTTPD>. I will
117 be notified, and then you'll automatically be notified of progress on
118 your bug as I make changes.
121 You can find documentation for this module with the perldoc command.
123 perldoc AnyEvent::HTTPD
125 You can also look for information at:
127 * RT: CPAN's request tracker
129 <http://rt.cpan.org/NoAuth/Bugs.html?Dist=AnyEvent-HTTPD>
131 * AnnoCPAN: Annotated CPAN documentation
133 <http://annocpan.org/dist/AnyEvent-HTTPD>
137 <http://cpanratings.perl.org/d/AnyEvent-HTTPD>
141 <http://search.cpan.org/dist/AnyEvent-HTTPD>
145 Copyright 2008 Robin Redeker, all rights reserved.
147 This program is free software; you can redistribute it and/or modify it
148 under the same terms as Perl itself.