Library
Module
Module type
Parameter
Class
Class type
Make(Encoding)(Client)
is a module that allows you to make calls to various Resto
(or EzResto
) services.
The calls are type safe: you must provide the correct parameters to the services which are automatically encoded according to Encoding
, the answer is automatically decoded according to Encoding
. The scheduling (waiting on answers, etc.) is provided by Client
.
Content-Type header specifications: https://tools.ietf.org/html/rfc7231#section-3.1.1.5 and additional information: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type
type raw_content = Cohttp_lwt.Body.t * content_type option
type content =
Cohttp_lwt.Body.t
* content_type option
* Resto_cohttp.Media_type.Make(Encoding).t option
type ('o, 'e) generic_rest_result = [
| `Ok of 'o option
200
*)| `Conflict of 'e
409
*)| `Error of 'e
500
*)| `Forbidden of 'e
403
*)| `Not_found of 'e
404
*)| `Gone of 'e
410
*)| `Bad_request of string
400
*)| `Method_not_allowed of string list
405
*)| `Unsupported_media_type
415
*)| `Not_acceptable of string
406
*)| `Unexpected_status_code of Cohttp.Code.status_code * content
HTTP status code set by server is invalid or unsupported by resto
*)| `Connection_failed of string
Failure at one of the levels lower than HTTP (e.g., network)
*)| `OCaml_exception of string
Exception raised whilst decoding the result.
*)| `Too_many_redirects of string
310
*)| `Redirect_without_location of string
Redirect did not have a Location header
*) ]
The type for possible results when calling over HTTP. Some results correspond to an HTTP return code, other results correspond to internal issues with resto.
module type LOGGER = sig ... end
A LOGGER
module is used for logging only
type logger = (module LOGGER)
val null_logger : logger
val timings_logger :
gettimeofday:(unit -> float) ->
Stdlib.Format.formatter ->
logger
val full_logger : Stdlib.Format.formatter -> logger
val generic_call :
[< Resto.meth ] ->
?redirect_behaviour:redirect_behaviour ->
?headers:(string * string) list ->
?accept:Resto_cohttp.Media_type.Make(Encoding).t list ->
?body:Cohttp_lwt.Body.t ->
?media:Resto_cohttp.Media_type.Make(Encoding).t ->
Uri.t ->
(content, content) generic_rest_result Lwt.t
Low-level call primitive: use only for making calls for which there is no service defined, prefer making call to a defined service.
type ('o, 'e) service_result = [
| ('o, 'e option) generic_rest_result
| `Unexpected_content_type of raw_content
| `Unexpected_content of
(string * Resto_cohttp.Media_type.Make(Encoding).t) * string
| `Unexpected_error_content_type of raw_content
| `Unexpected_error_content of
(string * Resto_cohttp.Media_type.Make(Encoding).t) * string
]
The type for possible results when calling a service. This includes the possible HTTP results (see generic_rest_result
and other service-specific errors.
val call_service :
Resto_cohttp.Media_type.Make(Encoding).t list ->
?redirect_behaviour:redirect_behaviour ->
?logger:logger ->
?headers:(string * string) list ->
?base:Uri.t ->
([< Resto.meth ], unit, 'p, 'q, 'i, 'o, 'e) Service.t ->
'p ->
'q ->
'i ->
(Resto.meth * Uri.t * ('o, 'e) service_result) Lwt.t
call_service media_types ?logger ?headers ?base service path_params
query_params input
makes a call to service
with the parameters path_params
, query_params
, and input
. It returns a result (or an error).
The OCaml type system guarantees that the parameters are as expected by the service.
val call_streamed_service :
Resto_cohttp.Media_type.Make(Encoding).t list ->
?redirect_behaviour:redirect_behaviour ->
?logger:logger ->
?headers:(string * string) list ->
?base:Uri.t ->
([< Resto.meth ], unit, 'p, 'q, 'i, 'o, 'e) Service.t ->
on_chunk:('o -> unit) ->
on_close:(unit -> unit) ->
'p ->
'q ->
'i ->
(Resto.meth * Uri.t * (unit -> unit, 'e) service_result) Lwt.t
call_streamed_service media_types ?logger ?headers ?base service
~on_chunk ~on_close path_params query_params input
makes a call to service
with the parameters path_params
, query_params
, and input
. The values returned by the service are passed to the on_chunk
callback, and when the server closes the connection the on_close
callback is called.
The function returns a unit -> unit
function that consumes the remainder of the input without side-effects. Call this function when you want to discard all the queued-up chunks.
The OCaml type system guarantees that the parameters are as expected by the service.