あなたが何をしたいのかよくわかりませんが、JSONについては、次のようにOCaml型を使用して「派生」( Deriving_Jsonを参照)を使用してJSON型を作成できます。
type deriving_t = (string * string) deriving (Json)
これにより、OCaml 型に対応する JSON 型が作成されます。
この型を使用してサーバーと通信する方法は次のとおりです (サーバー機能がわからない場合は、それに関するドキュメントとサーバー側のクライアント値に関するドキュメントを参照してください)。
(* first you have to create a server function (this allowed the client to call a function from the server *)
let json_call =
server_function
Json.t<deriving_t>
(fun (a,b) ->
Lwt.return (print_endline ("log on the server: "^a^b)))
(* let say that distillery has already generate all the needed stuff (main_service, Foobar_app, etc..) *)
let () =
Foobar_app.register
~service:main_service
(fun () () ->
{unit{
(* here I call my server function by using ocaml types directly, it will be automatically serialize *)
ignore (%json_call ("hello", "world"))
}};
Lwt.return
(Eliom_tools.F.html
~title:"foobar"
~css:[["css";"foobar.css"]]
Html5.F.(body [
h2 [pcdata "Welcome from Eliom's distillery!"];
])))
クライアント/サーバー通信を使用したい場合は、Eliom_bus、Eliom_comet、または Eliom_react を調べてください。
(申し訳ありませんが、2 つ以上のリンクを作成することはできません :) しかし、ドキュメントは ocsigen.org Web サイトにあります)。
それがあなたを助けることを願っています。