mirage/ocaml-rpc

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

Homepage:

Size: 455

Language: OCaml

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

OCaml-RPC

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.

Build Status

RPC types

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
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 sufficient to add [@@deriving rpc] to the corresponding type definition. Hence :

 t = ... [@@deriving rpc]

this will give two functions:

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.

Conversion functions

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)
Dependencies

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.