examples: annotate examples
[nit.git] / lib / nitcorn / nitcorn.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # The nitcorn Web server framework creates server-side Web apps in Nit
18 #
19 # The main classes are:
20 # * `Action` to answer to requests.
21 # * `Route` to represent a path to an action.
22 # * `VirtualHost` to listen on a specific interface and behave accordingly
23 # * `HttpFactory` which is the base dispatcher class.
24 #
25 # Basic usage example:
26 # ~~~~
27 # class MyAction
28 # super Action
29 #
30 # redef fun answer(http_request, turi)
31 # do
32 # var response = new HttpResponse(200)
33 # response.body = """
34 # <!DOCTYPE html>
35 # <head>
36 # <meta charset="utf-8">
37 # <title>Hello World</title>
38 # </head>
39 # <body>
40 # <p>Hello World</p>
41 # </body>
42 # </html>"""
43 # return response
44 # end
45 # end
46 #
47 # # Listen to port 8080 on all interfaces
48 # var vh = new VirtualHost("0.0.0.0:8080")
49 #
50 # # Serve index.html with our custom handler
51 # vh.routes.add new Route("/index.html", new MyAction)
52 #
53 # # Serve everything else with a standard `FileServer`
54 # vh.routes.add new Route(null, new FileServer("/var/www/"))
55 #
56 # var factory = new HttpFactory.and_libevent
57 # factory.config.virtual_hosts.add vh
58 # factory.run
59 # ~~~~
60 module nitcorn
61
62 import reactor
63 import file_server
64 import sessions
65 import signal_handler