Name: ocaml-rpc
Owner: MirageOS
Description: Light library to deal with RPCs in OCaml
Created: 2010-01-21 17:24:29.0
Updated: 2018-03-30 00:31:52.0
Pushed: 2018-03-23 16:57:05.0
Size: 455
Language: OCaml
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
ocaml-rpc
is a library that provides remote procedure calls (RPC)
using XML or JSON as transport encodings. The transport mechanism itself
is outside the scope of this library as all conversions are from and to
strings.
An RPC value is defined as follow:
t =
Int of int64
Bool of bool
Float of float
String of string
DateTime of string
Enum of t list
Dict of (string * t) list
Null
The idea behind ocaml-rpc
is to generate functions to convert values of a
given type to and from theirs RPC representations.
In order to do so, it is sufficient to add [@@deriving rpc]
to the
corresponding type definition. Hence :
t = ... [@@deriving rpc]
this will give two functions:
A function to convert values of type t
to values of type Rpc.t
:
val rpc_of_t : t -> Rpc.t
A function to convert values of type Rpc.t
to values of type t
:
val t_of_rpc : Rpc.t -> (t,string) Result.result
Optionally, it is possible to have different field name in the OCaml
type (if it is a record) and in the dictionary argument (the first
elements of Dict
):
t = { foo: int [@key "type"]; bar: int [@key "let"]; } [@@deriving rpc]
This will replace “foo” by “type” and “bar” by “let” in the RPC representation. This is particularly useful when you want to integrate with an existing API and the field names are not valid OCaml identifiers.
rpc
currently support two protocols: XMLRPC and JSON(RPC). Functions
signatures are:
Xmlrpc.to_string : Rpc.t -> string
Xmlrpc.of_string : string -> Rpc.t
Jsonrpc.to_string : Rpc.t -> string
Jsonrpc.of_string : string -> Rpc.t
So if you want to marshal a value x of type t to JSON, you can use the following function:
rpc.to_string (rpc_of_t x)