package json-rpc

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type id = [
  1. | `Int of int
  2. | `Null
  3. | `String of string
]

identifier for request/response/error messages

type json = Yojson.Basic.json
type t =
  1. | Request of {
    1. name : string;
    2. params : json option;
    3. id : id;
    }
  2. | Notification of {
    1. name : string;
    2. params : json option;
    }
  3. | Response of {
    1. result : json;
    2. id : id;
    }
  4. | Error of {
    1. code : int;
    2. message : string;
    3. data : json option;
    4. id : id;
    }
    (*

    type of a JSON-RPC 2.0 message

    *)
val request : id:id -> ?params:json -> string -> json

request ~id ~params name generates a request message with method name name, identifier id and parameters params directly as JSON value. request ~id ~params name = to_json (Request { name; params; id })

val notification : ?params:json -> string -> json

notification ~params name generate a notification message with method name name and parameters params directly as JSON value. notification ~params name = to_json (Notification { name; params }

val response : id:id -> json -> json

response ~id data generates a response message with identifier id and payload data directly as JSON value. response ~id result = to_json (Response { result; id })

val error : id:id -> ?data:json -> int -> string -> json

error ~id ~data code message generates an error message with identifier id and error-triplet code, message and optionally data. error ~id ~data code message = to_json (Error { code; message; data; id })

val to_json : t -> json

convert a message type t to JSON

val to_string : t -> string

convert a message type t to string

val of_json : json -> (t, string) Result.result

parse a JSON value to a JSON-RPC message value; in case of an error, Result.Error is returned.

val of_json_exn : json -> t

parse a JSON value to a JSON-RPC message value; in case of an error, Invalid_argument is raised.

val of_string : string -> (t, string) Result.result

parse a JSON value to a JSON-RPC message value from a string; in case of an error, Result.Error is returned.

val of_string_exn : string -> t

parse a JSON value to a JSON-RPC message value from a string; in case of an error either Invalid_argument or Yojson.Json_error are raised.

module Server : sig ... end
OCaml

Innovation. Community. Security.