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

How to call a server side function from client side?

It is possible to call server side functions in client side code using the % syntax. But for security reason, these functions must first be declared explicitely as "server functions" (with the type of their argument).

let f x = ...


  let f_rpc = %(server_function Json.t<int> f)


     ... f_rpc 4 ...

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

If the function takes a more complex type, this type 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 while unmarshaling corrupted data).


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