Warning: Reason support is experimental. We are looking for beta-tester and contributors.

How to make the client side program get an HTML element from the server and insert it in the page?

A very convenient way to do that is to use server functions :

let get_mydiv () = div [ ... ]


  let get_mydiv_rpc = %(server_function Json.t<unit> get_mydiv)


     lwt mydiv = get_mydiv_rpc () in
     Dom.appendChild parent (To_dom.of_element mydiv)

Server functions take exactly one parameter.

Server functions are just syntactic sugar for non-attached coservices returning OCaml values.

The type of the function parameter must have been declared with the JSON module of deriving. This makes possible for the server to check the data that are sent (and avoid crashing).


type t = (int * string)  deriving(Json)