Writing a client/server Eliom application

The code of this tutorial has been tested against Eliom 4.

In this chapter, we will write a collaborative drawing application. It is a client/server web application displaying an area where users can draw using the mouse, and see what other users are drawing at the same time and in real-time.

The final eliom code is available for download.

Basics

To get started, we recommend to use Eliom's distillery, a program which creates scaffolds for Eliom projects. The following command creates a very simplicistic project called "graffiti" in the directory "graffiti" (adapt it to your needs!):

$ eliom-distillery -name graffiti -template basic -target-directory graffiti

My first page

Our web application consists of a single page for now. Let's start by creating a very basic page. We define the service that will implement this page by the following declaration:

open Eliom_content.Html5.D (* provides functions to create HTML nodes *)

let main_service =
  Eliom_registration.Html5.register_service
    ~path:["graff"]
    ~get_params:Eliom_parameter.unit
    (fun () () ->
      Lwt.return
        (html
           (head (title (pcdata "Page title")) [])
           (body [h1 [pcdata "Graffiti"]])