1 Lightweight framework for Web applications development
5 Dynamic content is served by subclassing `Action` and implementing `answer`.
6 This method receives an `HttpRequest` and must return an `HttpResponse`.
7 _nitcorn_ provides `FileServer`, a simple `Action` to serve static files.
9 `HttpRequest` contains the GET and POST arguments as well as session data it one exists.
10 The produced `HttpResponse` should contain the HTTP status code, the body,
11 session data to preserve or create a session, and optionally list files to append.
13 Each `Action` may be associated to many instances of `Route`.
14 These routes can simply identify the root of a service,
15 but also define parameters within the URI.
17 _nitcorn_ instances are configured dynamically in Nit code with the interfaces and routes created as needed.
19 _nitcorn_ plays well with other Nit services and tools such as `serialization`, `mongodb`, `sqlite` and `nitiwiki`.
20 It also benefits from the full power of the Nit language:
21 class refinement can be used to customize default services and merge many applications in a single server,
22 and the FFI enables calling services in different languages.
26 A minimal example follows with a custom `Action` and using `FileServer`.
28 More general examples are available at `lib/nitcorn/examples/`.
29 For an example of a larger project merging many _nitcorn_ applications into one server,
30 take a look at the configuration of `http://xymus.net/` at `../contrib/xymus_net/xymus_net.nit`.
32 Larger projects using _nitcorn_ can be found in the `contrib/` folder:
33 * _opportunity_ is a meetup planner heavily based on _nitcorn_.
34 * _tnitter_ is a micro-blogging platform with a simple Web and RESTful interface.
35 * _benitlux_ uses a custom `Action` to subscribe people to a mailing list and define a RESTful interface.
37 ## Simple hello world server
42 # Simple Action to display the Hello World page and the get arguments
43 class HelloWorldAction
46 redef fun answer(http_request, turi)
48 var title = "Hello World!"
49 var args = http_request.get_args.join(",", ":")
51 var response = new HttpResponse(200)
56 <meta charset="utf-8">
57 <title>{{{title}}}</title>
61 <p>GET args: {{{args}}}</p>
68 # Listen on `localhost:8080`
69 var vh = new VirtualHost("localhost:8080")
71 # Serve `http://localhost:8080/hello.html` with our custom action
72 vh.routes.add new Route("/hello.html", new HelloWorldAction)
74 # Serve everything else under `http://localhost:8080/` using a `FileServer` with a root at "/var/www/"
75 vh.routes.add new Route(null, new FileServer("/var/www/"))
78 var factory = new HttpFactory.and_libevent
79 factory.config.virtual_hosts.add vh
85 This nitcorn library is a fork from an independent project originally created in 2013 by
86 Jean-Philippe Caissy, Guillaume Auger, Frederic Sevillano, Justin Michaud-Ouellette,
87 Stephan Michaud and Maxime Bélanger.
89 It has been adapted to a library, and is currently maintained, by Alexis Laferrière.