Implementing Web Interaction Using Eliom

The code of this tutorial has been tested with Eliom 6.0.

This chapter of the tutorial explains how to create a small web site with several pages, users, sessions, and other elements of classical web development. Then, in next chapter, we will incorporate the features of this site with the program from the previous chapter, to show that we can mix this kind of interaction with client-side programs.

We assume you have read at least the first section of the previous chapter, which explained how to create a service and constuct valid HTML pages.

We will create a simple web site with one main page and a page for each user (assuming we have several users already created). Then we will add a login/connection form. We will also add a registration form, in order to learn how to create dynamically new services, and why it is very useful.

The full code of the program can be downloaded.


The main page

Let's start again from scratch with the following site.

let main_service = Eliom_content.Html.D.(
    ~path:(Eliom_service.Path [""])
    ~meth:(Eliom_service.Get Eliom_parameter.unit)
    (fun () () ->
        (html (head (title (pcdata "")) [])
           (body [h1 [pcdata "Hello"]])))

Note that we are using Eliom_registration.Html, as we are not building a client side program for now.

For the same reason, you may want to remove the .eliom-file generated by the distillery and put the code into an .ml-file. But don't forget to add it to the server files in the Makefile.options:


Adding a page for each user

We will now create a page for each user. To do this, we will create a new service, taking the user name as parameter:

let user_service = Eliom_content.Html.D.(