1
http://ocsigen.org/eliom/manual/server-params#h5o-3显示了一个接受用户定义类型的GET服务的示例。我想从客户端调用带有user_type的coservice,在客户端使用相同的类型。现在看来似乎应该是可能的,但我得到我该如何将Eliom客户端的user_type传递给服务器?
ocsigenserver: main: Exn during page generation: Failure("User service parameters 'foo' type not supported client side.") (sending 500)
当我尝试
{shared{
open Eliom_lib
open Eliom_content
open Html5.D
type foo = A | B
let foo_of_string = function "a" -> A | "b" -> B | _ -> raise (Failure "foo_of_string: unsupported foo")
let string_of_foo = function A -> "a" | B -> "b"
}}
let foo_to_div foo : Html5_types.div Html5.elt Lwt.t = match foo with A -> Lwt.return (div [pcdata "aye"]) | B -> Lwt.return (div [pcdata "bee"])
let foo_service =
Eliom_registration.Ocaml.register_post_coservice'
~post_params:Eliom_parameter.(user_type foo_of_string string_of_foo "foo")
(fun() foo -> foo_to_div foo)
{client{
let test() =
Eliom_client.call_ocaml_service ~service:%foo_service() A
}}
(* Boilerplate from eliom-distillery: *)
module Testing_app = Eliom_registration.App
(struct let application_name = "testing" end)
let main_service =
Eliom_service.App.service ~path:[] ~get_params:Eliom_parameter.unit()
let() =
Testing_app.register ~service:main_service
(fun()() -> Lwt.return (Eliom_tools.F.html ~title:"foo"
Html5.F.(body [ pcdata "bar" ])))
我也尝试使用server_function,但后来我跑进如何获得的问题div作为json;做
type div_elt = Html5_types.div Eliom_content.Html5.elt
let div_elt_json = Json.t<div_elt>
给我Error: Unbound module Html5_types.Json_div