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 It includes the configuration of `http://xymus.net/` which merges many other _nitcorn_ applications.
31 Larger projects using _nitcorn_ can be found in the `contrib/` folder:
32 * _opportunity_ is a meetup planner heavily based on _nitcorn_.
33 * _tnitter_ is a micro-blogging platform with a simple Web and RESTful interface.
34 * _benitlux_ uses a custom `Action` to subscribe people to a mailing list and define a RESTful interface.
36 ## Simple hello world server
41 # Simple Action to display the Hello World page and the get arguments
42 class HelloWorldAction
45 redef fun answer(http_request, turi)
47 var title = "Hello World!"
48 var args = http_request.get_args.join(",", ":")
50 var response = new HttpResponse(200)
55 <meta charset="utf-8">
56 <title>{{{title}}}</title>
60 <p>GET args: {{{args}}}</p>
67 # Listen on `localhost:8080`
68 var vh = new VirtualHost("localhost:8080")
70 # Serve `http://localhost:8080/hello.html` with our custom action
71 vh.routes.add new Route("/hello.html", new HelloWorldAction)
73 # Serve everything else under `http://localhost:8080/` using a `FileServer` with a root at "/var/www/"
74 vh.routes.add new Route(null, new FileServer("/var/www/"))
77 var factory = new HttpFactory.and_libevent
78 factory.config.virtual_hosts.add vh
84 This nitcorn library is a fork from an independent project originally created in 2013 by
85 Jean-Philippe Caissy, Guillaume Auger, Frederic Sevillano, Justin Michaud-Ouellette,
86 Stephan Michaud and Maxime Bélanger.
88 It has been adapted to a library, and is currently maintained, by Alexis Laferrière.