package eliom

  1. Overview
  2. Docs
Advanced client/server Web and mobile framework

Install

Dune Dependency

Authors

Maintainers

Sources

10.4.0.tar.gz
md5=87e171413ab2714514019b533f3f7ab3
sha512=e3ed10c599dd54bc5d4b1bf67debb7068f439d33e30dd39e5ed0cebbddd700b9765a751e16fa93dbd1fa6d934fbb6b2d1677fce817fbfea70565192a0a7e1025

Description

Eliom is a framework for implementing Web sites and client/server Web and mobile applications. It uses advanced concepts to simplify the implementation of common behaviors (e.g. scoped sessions, continuation based Web programming ...). It uses advanced static typing features of OCaml to check many properties of the Web application at compile-time (html, page parameters ...). Eliom allows implementing the whole application as a single program that includes both the client and the server code. For example, you can implement event handlers (onclick ...) directly in OCaml, and you can call a server-side OCaml function from the client. Pages are generated either on the server or the client. These client-side features remain compatible with traditional Web programming (links, forms, URLs, bookmarks, sessions ...). It is possible to generate mobile applications for Android and iOS with the exact same code as your Web application. The client-side code is compiled to JS using Ocsigen Js_of_ocaml or to Wasm using Wasm_of_ocaml.

Published: 28 Mar 2024

README

Eliom - the full-stack OCaml Web and mobile framework

Eliom is a framework for building client/server Web and mobile applications in OCaml.

It can be used both as a traditional server-side Web framework or to implement complex client-server applications.

Eliom transforms OCaml into a multi-tier language, making it possible to implement both the server and client parts of a Web and mobile app as a single program.

This simplifies a lot the communication between server and client. Applications can run on any Web browser or mobile device (iOS, Android), saving from the need to develop one version for each platform.

Eliom has support for reactive pages (generated on server or client), advanced session mechanism, server to client communication, continuation based Web programming, etc.

Eliom is part of the Ocsigen project.

Installation Instructions

opam install eliom

Getting started

Defining a service on path /foo, taking any GET parameters:

let myservice =
  Eliom_service.create
    ~path:(Eliom_service.Path ["foo"])
    ~meth:(Eliom_service.Get (Eliom_parameter.any))
    ()

let () =
  Eliom_registration.Html.register ~service:myservice
    (fun get_params () ->
      Lwt.return
         Eliom_content.Html.F.(html (head (title (txt "")))
                                    (body [h1 [txt "Hello"]])))

Inserting a link towards that service, with parameters:

Eliom_content.Html.D.a ~service:myservice [txt "Home"] [("param1", "v1"); ("param2", "v2")]

Event handlers are written in OCaml:

div ~a:[a_onclick [%client (fun ev -> ... )]] [ ... ]

The client-side and server sides are written as a single program:

let%server a = ... (* code for the server part of the application *)

let%client b = ... (* code for the client part of the application *)

let%shared c = ... (* code that will be included in both parts *)

Using a server-side value in client-side code:

let%server a = ...

let%client f () =
  print_endline ~%a ; (* print in browser console *)
  ...

Calling a server function from the client program:

let%rpc f (x : int) : string Lwt.t = ... (* server-side code *)

let%client () =
  let%lwt r = f 4 in
  ...

Saving session data on the server using Eliom references:

let%server r = Eliom_reference.eref ~scope:Eliom_common.default_session_scope 0

let%server f () =
  let%lwt v = Eliom_reference.get r in
  Eliom_reference.set r (v + 1);
  ...

Where scope can be:

  • Eliom_common.default_session_scope (different value for each browser),

  • Eliom_common.default_process_scope (different value for each tab),

  • Eliom_common.default_group_scope (different value for each user),

  • Eliom_common.site_scope (value for the whole site),

  • Eliom_common.global_scope (global value for the whole server). Eliom references are persistant if you add optional parameter ~persistent to function Eliom_reference.eref.

Learning Eliom

More documentation here.

Write your first Web and mobile application with Eliom using Ocsigen Start

Authors

  • Vincent Balat

  • Jérôme Vouillon

  • Grégoire Henry

  • Pierre Chambart

  • Benedikt Becker

  • Vasilis Papavasileiou

  • Boris Yakobowski

  • Hugo Heuzard

  • Raphaël Proust

  • Jan Rochel

  • Idir Lankri

  • Stéphane Glondu

  • Gabriel Radanne

  • Gabriel Kerneis

  • Denis Berthod

  • Jaap Boender

  • Simon Castellan

  • Mauricio Fernandez

  • Archibald Pontier

  • Simon Castellan

  • Kate Deplaix

Dependencies (21)

  1. ppx_optcomp
  2. ocsipersist >= "1.0" & < "2.0"
  3. base-bytes
  4. reactiveData >= "0.2.1"
  5. ipaddr >= "2.1"
  6. ocsigenserver >= "5.1.0" & < "6.0.0"
  7. tyxml >= "4.6.0" & < "4.7.0"
  8. lwt_ppx >= "1.2.3"
  9. lwt_log
  10. js_of_ocaml-tyxml >= "3.6.0"
  11. js_of_ocaml-ppx_deriving_json >= "3.6.0"
  12. js_of_ocaml-ppx >= "3.6.0"
  13. js_of_ocaml-ocamlbuild build
  14. js_of_ocaml-lwt >= "3.6.0"
  15. js_of_ocaml >= "3.6.0"
  16. js_of_ocaml-compiler >= "3.6.0"
  17. ppxlib >= "0.15.0"
  18. ppx_deriving
  19. ocamlfind
  20. ocaml >= "4.08.0" & < "5.2"
  21. dune >= "3.6"

Dev Dependencies (1)

  1. odoc with-doc

Used by (2)

  1. ocsigen-start = "6.3.0"
  2. ocsigen-toolkit >= "1.1.0" & < "4.0.0"

Conflicts

None

OCaml

Innovation. Community. Security.