Library
Module
Module type
Parameter
Class
Class type
The different chunks of a path
E.g., /archive/<year>/<months>/
has a Static "archive"
step followed by a Dynamic _
step followed by a Dynamic _
step. Each Dynamic _
step has an Resto.Arg
payload describing the chunk.
type 'prefix directory = 'prefix t
val string_of_step : step -> string
string_of_step step
converts the given steps
into a string.
val string_of_conflict_kind : conflict -> string
string_of_conflict_kind conflict_kind
converts the given conflict_kind
into a string.
string_of_conflict conflict
converts the given conflict
into a string.
val lookup :
'prefix directory ->
'prefix ->
Resto.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 lookup_uri_desc :
'prefix directory ->
'prefix ->
Resto.meth ->
string list ->
(string, [> lookup_error ]) Stdlib.result Lwt.t
lookup_uri_desc d p
is Ok u
where u
is a formated URI description, if there is a service s
registered in d
and the path of s
matches p
. It is Error _
otherwise.
For instance, given the following path p
: "/entries-by-date/2022/01/10"
where "2022"
, "01"
, and "10"
are expected to be paramaters in the path of s
, the function will evaluate in "/entries-by-date/<year>/<month>/<day>"
.
val allowed_methods :
'prefix directory ->
'prefix ->
string list ->
(Resto.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
.
val empty : 'prefix 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
.
val merge :
?strategy:[ `Raise | `Pick_left | `Pick_right ] ->
'a directory ->
'a directory ->
'a directory
merge ~strategy d1 d2
is a directory which includes all the services of d1
and d2
.
If one or more service from d1
collides with one or more service from d2
, the function will make a choice depending on the given merging strategy
:
`Raise
will raise a Conflict
exception. This is the default choice.`Pick_left
will pick the service from d1
to be part of the resulting directory.`Pick_right
will pick the service from d2
to be part of the resulting directory.Be careful, this function is only capable to merge static directory trees. If a subtree of one of the given directory is dynamic, the function will raise a Conflict
exception.
val register :
'prefix directory ->
('meth, 'prefix, 'params, 'query, 'input, 'output, 'error) Service.t ->
('params -> 'query -> 'input -> [< ('output, 'error) Answer.t ] Lwt.t) ->
'prefix 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
.
val register0 :
unit directory ->
('m, unit, unit, 'q, 'i, 'o, 'e) Service.t ->
('q -> 'i -> [< ('o, 'e) Answer.t ] Lwt.t) ->
unit directory
Registring handler in service tree. Curryfied variant.
val register_dynamic_directory :
?descr:string ->
'prefix directory ->
('prefix, 'a) Resto.Path.path ->
('a -> 'a directory Lwt.t) ->
'prefix directory
Registring dynamic subtree.
val register_dynamic_directory1 :
?descr:string ->
'prefix directory ->
('prefix, unit * 'a) Resto.Path.path ->
('a -> (unit * 'a) directory Lwt.t) ->
'prefix directory
Registring dynamic subtree. (Curryfied variant)