nitcorn

module nitcorn

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

Dependencies

dep_module_nitcorn__nitcornfile_serverfile_serverhttp_errorshttp_errorsfile_server->http_errorsmedia_typesmedia_typesfile_server->media_typesreactorreactorfile_server->reactorsessionssessionsfile_server->sessionshttp_responsehttp_responsehttp_errors->http_responsereactor->http_responsehttp_request_bufferhttp_request_bufferreactor->http_request_buffervararg_routesvararg_routesreactor->vararg_routessessions->http_responsehttp_requesthttp_requestsessions->http_requestserver_configserver_configsessions->server_configtokentokensessions->tokenvararg_routes->http_requestvararg_routes->server_configlogloglog->reactornitcornnitcornnitcorn->file_serversignal_handlersignal_handlernitcorn->signal_handlersignal_handler->reactorproxyproxyproxy->reactorpthreadspthreadspthreads->nitcornrestfulrestfulrestful->nitcornhookshookshooks->nitcornpop_routespop_routespop_routes->nitcornhtcpcp_serverhtcpcp_serverhtcpcp_server->nitcornnitcorn_hello_worldnitcorn_hello_worldnitcorn_hello_world->nitcornsimple_file_serversimple_file_serversimple_file_server->nitcorn

Imports

  • file_server: Provides the FileServer action, which is a standard and minimal file server
  • signal_handler: Handle SIGINT and SIGTERM to close the server after all active events

Clients

  • hooks: Github hook event listening with nitcorn.
  • htcpcp_server: A server that implements HTCPCP. At the moment there are no additions.
  • nitcorn_hello_world: Hello World Web server example
  • pop_routes: Internal routes representation.
  • pthreads: Activate the use of pthreads with nitcorn
  • restful: Support module for the nitrestful tool and the restful annotation
  • simple_file_server: Basic file server on port 80 by default, may require root to execute