Lightweight framework for Web applications development


Dynamic content is served by subclassing Action and implementing answer. This method receives an HttpRequest and must return an HttpResponse. nitcorn provides FileServer, a simple Action to serve static files.

HttpRequest contains the GET and POST arguments as well as session data it one exists. The produced HttpResponse should contain the HTTP status code, the body, session data to preserve or create a session, and optionally list files to append.

Each Action may be associated to many instances of Route. These routes can simply identify the root of a service, but also define parameters within the URI.

nitcorn instances are configured dynamically in Nit code with the interfaces and routes created as needed.

nitcorn plays well with other Nit services and tools such as serialization, mongodb, sqlite and nitiwiki. It also benefits from the full power of the Nit language: class refinement can be used to customize default services and merge many applications in a single server, and the FFI enables calling services in different languages.


A minimal example follows with a custom Action and using FileServer.

More general examples are available at lib/nitcorn/examples/. For an example of a larger project merging many nitcorn applications into one server, take a look at the configuration of at ../contrib/xymus_net/xymus_net.nit.

Larger projects using nitcorn can be found in the contrib/ folder:

  • opportunity is a meetup planner heavily based on nitcorn.
  • tnitter is a micro-blogging platform with a simple Web and RESTful interface.
  • benitlux uses a custom Action to subscribe people to a mailing list and define a RESTful interface.

Simple hello world server

import nitcorn

# Simple Action to display the Hello World page and the get arguments
class HelloWorldAction
    super Action

    redef fun answer(http_request, turi)
        var title = "Hello World!"
        var args = http_request.get_args.join(",", ":")

        var response = new HttpResponse(200)
        response.body = """
<!DOCTYPE html>
    <meta charset="utf-8">
    <p>GET args: {{{args}}}</p>
        return response

# Listen on `localhost:8080`
var vh = new VirtualHost("localhost:8080")

# Serve `http://localhost:8080/hello.html` with our custom action
vh.routes.add new Route("/hello.html", new HelloWorldAction)

# Serve everything else under `http://localhost:8080/` using a `FileServer` with a root at "/var/www/"
vh.routes.add new Route(null, new FileServer("/var/www/"))

# Launch server
var factory = new HttpFactory.and_libevent
factory.config.virtual_hosts.add vh


This nitcorn library is a fork from an independent project originally created in 2013 by Jean-Philippe Caissy, Guillaume Auger, Frederic Sevillano, Justin Michaud-Ouellette, Stephan Michaud and Maxime Bélanger.

It has been adapted to a library, and is currently maintained, by Alexis Laferrière.

All groups and modules

module file_server

nitcorn :: file_server

Provides the FileServer action, which is a standard and minimal file server
module http_errors

nitcorn :: http_errors

Offers ErrorTemplate to display error pages
module http_request

nitcorn :: http_request

Provides the HttpRequest class and services to create it
module http_request_buffer

nitcorn :: http_request_buffer

Http request parsing for buffered inputs.
module http_response

nitcorn :: http_response

Provides the HttpResponse class and http_status_codes
module log

nitcorn :: log

Services inserting a timestamp in all prints and to log each requests
module media_types

nitcorn :: media_types

Services to identify Internet media types (or MIME types, Content-types)
module nitcorn

nitcorn :: nitcorn

The nitcorn Web server framework creates server-side Web apps in Nit
module proxy

nitcorn :: proxy

Provides the ProxyAction action, which redirects requests to another interface
module pthreads

nitcorn :: pthreads

Activate the use of pthreads with nitcorn
module reactor

nitcorn :: reactor

Core of the nitcorn project, provides HttpFactory and Action
module restful

nitcorn :: restful

Support module for the nitrestful tool and the restful annotation
module server_config

nitcorn :: server_config

Classes and services to configure the server
module sessions

nitcorn :: sessions

Automated session management
module signal_handler

nitcorn :: signal_handler

Handle SIGINT and SIGTERM to close the server after all active events
module token

nitcorn :: token

Simple generate_token service, independent of the rest of the nitcorn framework
module vararg_routes

nitcorn :: vararg_routes

Routes with parameters.
package_diagram nitcorn nitcorn ...nitcorn ... ...nitcorn->nitcorn github github github->nitcorn popcorn popcorn popcorn->nitcorn popcorn->github popcorn... ... popcorn...->popcorn


package meta


Simple user-defined meta-level to manipulate types of instances as object.
package opts


Management of options on the command line
package parser_base


Simple base for hand-made parsers of all kinds
package poset


Pre order sets and partial order set (ie hierarchies)
package posix


Services conforming to POSIX
package realtime


Services to keep time of the wall clock time


package base64


Offers the base 64 encoding and decoding algorithms
package core


Nit common library of core classes and methods
package curl


Data transfer powered by the native curl library
package json


read and write JSON formatted text
package libevent


Low-level wrapper around the libevent library to manage events on file descriptors
package md5


Native MD5 digest implementation as Text::md5
package more_collections


Highly specific, but useful, collections-related classes.
package performance_analysis


Services to gather information on the performance of events by categories
package privileges


Process privileges management utilities
package pthreads


POSIX Threads support
package serialization


Abstract serialization services
package template


Basic template system


package github


Nit wrapper for Github API
package popcorn