serverino

Serverino is a small and ready-to-go http server, in D. It is multiplatform and compiles with DMD, LDC and GDC.

The following example shows how to create a server that responds to all requests with the request dump, in a few lines of code.

import serverino;
mixin ServerinoMain;
void hello(const Request req, Output output) { output ~= req.dump(); }

serverino.interfaces.Request is the request object received, and serverino.interfaces.Output is the output you can write to.

A more complete example is the following:

import serverino;
mixin ServerinoMain;

@onServerInit ServerinoConfig setup()
{
   ServerinoConfig sc = ServerinoConfig.create(); // Config with default params
   sc.addListener("127.0.0.1", 8080);
   sc.setWorkers(2);
   // etc...

   return sc;
}

@endpoint
void dump(const Request req, Output output) { output ~= req.dump(); }

@endpoint @priority(1)
@route!"/hello"
void hello(const Request req, Output output) { output ~= "Hello, world!"; }

The function decorated with serverino.config.onServerInit is called when the server is initialized, and it is used to configure the server. It must return a serverino.config.ServerinoConfig object. In this example, the server is configured to listen on localhost:8080, with 2 workers.

Every function decorated with serverino.config.endpoint is an endpoint. They are called in order of priority assigned with serverino.config.priority (default is 0). The first endpoint that write something to the output is the one that will respond to the request.

The serverino.config.route attribute can be used to filter the requests that are passed to the endpoint, using a uri or a bool delegate(Request r) argument. In this example, only requests to /hello are passed to the hello endpoint. The serverino.config.route attribute can be used multiple times to specify multiple routes also using a delegate.

Modules

common
module serverino.common
Undocumented in source.
communicator
module serverino.communicator
Undocumented in source.
config
module serverino.config

Configuration module for serverino.

daemon
module serverino.daemon
Undocumented in source.
databuffer
module serverino.databuffer
Undocumented in source.
interfaces
module serverino.interfaces

Everything you need to communicate.

main
module serverino.main
Undocumented in source.
tests
module serverino.tests
Undocumented in source.
worker
module serverino.worker
Undocumented in source.

Public Imports

serverino.main
public import serverino.main;
Undocumented in source.
serverino.config
public import serverino.config;
Undocumented in source.
serverino.interfaces
public import serverino.interfaces;
Undocumented in source.

Meta