package ezresto-directory

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module EzResto_directorySource

Directories are sets of services. They are used to spin up servers (see Server) that reply to requests for all their registered services.

Sourcemodule Answer : sig ... end
Sourcetype step =
  1. | Static of string
  2. | Dynamic of EzResto.Arg.descr
  3. | DynamicTail of EzResto.Arg.descr

Possible error while registering services.

Sourcetype conflict =
  1. | CService of EzResto.meth
  2. | CDir
  3. | CBuilder
  4. | CTail
  5. | CTypes of EzResto.Arg.descr * EzResto.Arg.descr
  6. | CType of EzResto.Arg.descr * string list
Sourceexception Conflict of step list * conflict
Sourcetype directory

A set of services on which requests can be dispatched.

Sourceval empty : directory

Empty tree

prefix p d is a directory of services which includes a service registered on the path p / q for each service registered on the path q in d.

  • raises [Invalid_argument]

    if p is a dynamic path.

merge d1 d2 is a directory which includes all the services of d1 and d2.

  • raises [Conflict]

    if one or more service from d1 conflicts with one or more service from d2.

Registered services (with existential types for parameters and such).

Sourcetype 'input input =
  1. | No_input : unit input
  2. | Input : 'input Json_encoding.encoding -> 'input input
Sourcetype ('q, 'i, 'o, 'e) types = {
  1. query : 'q Resto.Query.t;
  2. input : 'i input;
  3. output : 'o Json_encoding.encoding;
  4. error : 'e Json_encoding.encoding;
}
Sourcetype registered_service =
  1. | Service : {
    1. types : ('q, 'i, 'o, 'e) types;
    2. handler : 'q -> 'i -> ('o, 'e) Answer.t Lwt.t;
    } -> registered_service

Resolve a service.

Sourcetype lookup_error = [
  1. | `Not_found
  2. | `Method_not_allowed of EzResto.meth list
  3. | `Cannot_parse_path of string list * EzResto.Arg.descr * string
]
Sourceval lookup : directory -> EzResto.meth -> string list -> (registered_service, [> lookup_error ]) result Lwt.t

lookup d m p is Ok (Service _) if there is a service s registered in d and both the method of s is m and the path of s matches p. It is Error _ otherwise.

If it is Ok (Service _) then the returned value corresponds to the registered service.

Sourceval allowed_methods : directory -> string list -> (EzResto.meth list, [> lookup_error ]) result Lwt.t

allowed_methods d p is the set of methods m such that lookup d m p is Ok _. In other words, it is the set of methods m such that a service has been registered in d for a path that matches p.

Sourceval transparent_lookup : directory -> ('meth, 'params, 'query, 'input, 'output, 'error) EzResto.service -> 'params -> 'query -> 'input -> [> ('output, 'error) Answer.t ] Lwt.t

Registering a handler to a service in a directory.

Sourceval register : directory -> ('meth, 'params, 'query, 'input, 'output, 'error) EzResto.service -> ('params -> 'query -> 'input -> ('output, 'error) Answer.t Lwt.t) -> directory

register d s h is a directory that contains all the services registered in d plus the service s. Requests to the service s are handled by the handler h.

Below are variants of the register function curryfied for specific arity of services.

Sourceval register0 : directory -> ('meth, unit, 'q, 'i, 'o, 'e) EzResto.service -> ('q -> 'i -> ('o, 'e) Answer.t Lwt.t) -> directory
Sourceval register1 : directory -> ('meth, unit * 'a, 'q, 'i, 'o, 'e) EzResto.service -> ('a -> 'q -> 'i -> ('o, 'e) Answer.t Lwt.t) -> directory
Sourceval register2 : directory -> ('meth, (unit * 'a) * 'b, 'q, 'i, 'o, 'e) EzResto.service -> ('a -> 'b -> 'q -> 'i -> ('o, 'e) Answer.t Lwt.t) -> directory
Sourceval register3 : directory -> ('meth, ((unit * 'a) * 'b) * 'c, 'q, 'i, 'o, 'e) EzResto.service -> ('a -> 'b -> 'c -> 'q -> 'i -> ('o, 'e) Answer.t Lwt.t) -> directory
Sourceval register4 : directory -> ('meth, (((unit * 'a) * 'b) * 'c) * 'd, 'q, 'i, 'o, 'e) EzResto.service -> ('a -> 'b -> 'c -> 'd -> 'q -> 'i -> ('o, 'e) Answer.t Lwt.t) -> directory
Sourceval register5 : directory -> ('meth, ((((unit * 'a) * 'b) * 'c) * 'd) * 'e, 'q, 'i, 'o, 'e) EzResto.service -> ('a -> 'b -> 'c -> 'd -> 'e -> 'q -> 'i -> ('o, 'e) Answer.t Lwt.t) -> directory
Sourceval register_dynamic_directory : ?descr:string -> directory -> 'params EzResto.Path.t -> ('params -> directory Lwt.t) -> directory

Registring dynamic subtree.

Sourceval register_dynamic_directory1 : ?descr:string -> directory -> (unit * 'a) EzResto.Path.t -> ('a -> directory Lwt.t) -> directory

Registring dynamic subtree. (Curryfied variant)

Sourceval register_dynamic_directory2 : ?descr:string -> directory -> ((unit * 'a) * 'b) EzResto.Path.t -> ('a -> 'b -> directory Lwt.t) -> directory
Sourceval register_dynamic_directory3 : ?descr:string -> directory -> (((unit * 'a) * 'b) * 'c) EzResto.Path.t -> ('a -> 'b -> 'c -> directory Lwt.t) -> directory
Sourceval register_describe_directory_service : directory -> EzResto.description_service -> directory

Registering a description service.

OCaml

Innovation. Community. Security.