Ocsigen
Quickstart
guide
Vincent Balat
FUN-OCaml - Berlin
Sep 16-17 2024
Vincent Balat
FUN-OCaml - Berlin
Sep 16-17 2024
Use arrow keys to navigate
$ opam install ocsigen-start ocsipersist-sqlite-config
You can find these slides on ocsigen.org
and the source code of the sides with the solution of
exercices on Github.
Refer to the main one page user manual to get more explanations.
Ocsigen Server
Eliom
Js_of_ocaml
Tyxml
Lwt
Ocsigen Start
Ocsigen Toolkit
Ocsigen i18n
Jérôme Vouillon, Vincent Balat
Pierre Chambart, Grégoire Henry, Benedikt Becker,
Vasilis Papavasileiou, Gabriel Radanne, Hugo Heuzard,
Benjamin Canou, Boris Yakobowski, Jan Rochel, Idir Lankri,
Jérémie Dimino, Romain Calascibetta, Raphaël Proust, Anton Bachin, Baptiste Strazzulla,
Julien Sagot, Stéphane Glondu, Gabriel Kerneis, Denis Berthod, Thorsten Ohl,
Danny Willems, Kate Deplaix, Enguerrand Decorne, Grégoire Lionnet,
Jaap Boender, Gabriel Scherer, Gabriel Cardoso, Yuta Sato, Sora Morimoto,
Christophe Lecointe, Arnaud Parant, Jérôme Maloberti, Charly Chevalier,
Jean-Henri Granarolo, Simon Castellan, Barbara Lepage, Séverine Maingaud,
Mauricio Fernandez, Michael Laporte, Nataliya Guts, Archibald Pontier,
Jérôme Velleine, Charles Oran, Pierre Clairambault,
Cécile Herbelin
…
The sports social network https://besport.com/news
$ ocsigenserver -c config
Where config
is something like:
<ocsigen>
<server>
<port>8080</port>
<commandpipe>local/var/run/mysite-cmd</commandpipe>
<logdir>local/var/log/mysite</logdir>
<datadir>local/var/data/mysite</datadir>
<charset>utf-8</charset>
<debugmode/>
<extension findlib-package="ocsigenserver.ext.staticmod"/>
<host hostfilter="mydomain.com">
<static dir="local/var/www/staticdir"/>
</host>
</server>
</ocsigen>
let () =
Ocsigen_server.start
[ Ocsigen_server.host [Staticmod.run ~dir:"static" ()]]
Example of Dune file for this program:
(executable
(public_name myproject)
(name main)
(libraries
ocsigenserver
ocsigenserver.ext.staticmod))
Compile with:
dune build
Find more complex configuration examples in the manual
Server-side session data is stored in Eliom references:
let r =
Eliom_reference.eref
~scope:Eliom_common.default_session_scope 0
let f () =
let%lwt v = Eliom_reference.get r in
Eliom_reference.set r (v + 1);
Eliom references have a scope!
Request | request_scope |
Tab | default_process_scope |
Session | default_session_scope |
Session group | default_group_scope |
Site | site_scope |
Global | global_scope |
Submiting this form sends the user name to a POST service, that will register your user name.
When the user name is already known, your main page displays this name, and a logout button.
Hints:
Eliom_state.discard_all
Test your app with several browsers to check that you can have several users simultaneously.
See the solution here.
Advanced version: instead of using a reference with scope session, create a session group whose name is the user name. Check that you can share session data across multiple browsers.
Services have many other features:
Example:
The form data will be saved in the closure!
Functional Web Programming!