The main classes are:
Action
to answer to requests.Route
to represent a path to an action.VirtualHost
to listen on a specific interface and behave accordinglyHttpFactory
which is the base dispatcher class.Basic usage example:
class MyAction
super Action
redef fun answer(http_request, turi)
do
var response = new HttpResponse(200)
response.body = """
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>Hello World</title>
</head>
<body>
<p>Hello World</p>
</body>
</html>"""
return response
end
end
# Listen to port 8080 on all interfaces
var vh = new VirtualHost("0.0.0.0:8080")
# Serve index.html with our custom handler
vh.routes.add new Route("/index.html", new MyAction)
# Serve everything else with a standard `FileServer`
vh.routes.add new Route(null, new FileServer("/var/www/"))
var factory = new HttpFactory.and_libevent
factory.config.virtual_hosts.add vh
factory.run
HttpRequest
class and services to create it
Serializable::inspect
to show more useful information
more_collections :: more_collections
Highly specific, but useful, collections-related classes.serialization :: serialization_core
Abstract services to serialize Nit objects to different formatscore :: union_find
union–find algorithm using an efficient disjoint-set data structureFileServer
action, which is a standard and minimal file server
root
to execute
restful
annotation documented at lib/nitcorn/restful.nit
# The nitcorn Web server framework creates server-side Web apps in Nit
#
# The main classes are:
# * `Action` to answer to requests.
# * `Route` to represent a path to an action.
# * `VirtualHost` to listen on a specific interface and behave accordingly
# * `HttpFactory` which is the base dispatcher class.
#
# Basic usage example:
# ~~~~
# class MyAction
# super Action
#
# redef fun answer(http_request, turi)
# do
# var response = new HttpResponse(200)
# response.body = """
# <!DOCTYPE html>
# <head>
# <meta charset="utf-8">
# <title>Hello World</title>
# </head>
# <body>
# <p>Hello World</p>
# </body>
# </html>"""
# return response
# end
# end
#
# # Listen to port 8080 on all interfaces
# var vh = new VirtualHost("0.0.0.0:8080")
#
# # Serve index.html with our custom handler
# vh.routes.add new Route("/index.html", new MyAction)
#
# # Serve everything else with a standard `FileServer`
# vh.routes.add new Route(null, new FileServer("/var/www/"))
#
# var factory = new HttpFactory.and_libevent
# factory.config.virtual_hosts.add vh
# factory.run
# ~~~~
module nitcorn
import reactor
import file_server
import sessions
import signal_handler
lib/nitcorn/nitcorn.nit:17,1--65,21