Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Light library to deal with RPCs in OCaml
OCaml Makefile
Latest commit 3bb3c1f @djs55 djs55 Merge pull request #34 from jonludlam/fix-encoding-off-by-one
Fix encoding off by one
Failed to load latest commit information.
lib Fix an off-by-one error in encoding XMLRPC
tests Add a simple test for the XMLRPC encoding issue.
.gitignore Add a Makefile rule to make the ml file generated from the idl
.travis.yml Add travis configuration
CHANGES Add travis configuration
INSTALL Make the dependency on js_of_ocaml optional
Makefile Makefile: add 'release' and 'pr' targets Completely remove any mention to `light` in the source code
opam Add opam file for easy development

ocaml-rpc is a libraries to deal with RPCs in ocaml.

RPC types

An RPC value is defined as follow:

type 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

Generating code

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 sufficicient to add with rpc to the corresponding type defintion. Hence :

type t = ... with 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

Optionaly, it is possible to have different field name in the OCaml type (if it is a record) and in the dictionary argumenent (the first elements of Dict):

type t = { foo: int; bar: int }
with rpc ("foo" -> "type", "bar" -> "let")

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.

Conversion functions

rpc currently support two protocols: XMLRPC and JSON(RPC). Functions signatures are:

val Xmlrpc.to_string : Rpc.t -> string
val Xmlrpc.of_string : string -> Rpc.t
val Jsonrpc.to_string : Rpc.t -> string
val 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:

Jsonrpc.to_string (rpc_of_t x)


Something went wrong with that request. Please try again.