Library
Module
Module type
Parameter
Class
Class type
Directories are sets of services. They are used to spin up servers (see Server
) that reply to requests for all their registered services.
module Answer : sig ... end
Possible error while registering services.
val 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
.
merge d1 d2
is a directory which includes all the services of d1
and d2
.
Registered services (with existential types for parameters and such).
type ('q, 'i, 'o, 'e) types = {
query : 'q Resto.Query.t;
input : 'i input;
output : 'o Json_encoding.encoding;
error : 'e Json_encoding.encoding;
}
Resolve a service.
val lookup :
directory ->
EzResto.meth ->
string list ->
(registered_service, [> lookup_error ]) Stdlib.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.
val allowed_methods :
directory ->
string list ->
(EzResto.meth list, [> lookup_error ]) Stdlib.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
.
Registering a handler to a service in a directory.
val 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.
val register_dynamic_directory :
?descr:string ->
directory ->
'params EzResto.Path.t ->
('params -> directory Lwt.t) ->
directory
Registring dynamic subtree.
val register_dynamic_directory1 :
?descr:string ->
directory ->
(unit * 'a) EzResto.Path.t ->
('a -> directory Lwt.t) ->
directory
Registring dynamic subtree. (Curryfied variant)