package resto-cohttp-client

  1. Overview
  2. Docs

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.

Parameters

module Call : CALL

Signature

module Service : module type of struct include Resto.MakeService(Encoding) end
type content_type = string * string

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 ('o, 'e) generic_rest_result = [
  1. | `Ok of 'o option
    (*

    200

    *)
  2. | `Conflict of 'e
    (*

    409

    *)
  3. | `Error of 'e
    (*

    500

    *)
  4. | `Forbidden of 'e
    (*

    403

    *)
  5. | `Not_found of 'e
    (*

    404

    *)
  6. | `Gone of 'e
    (*

    410

    *)
  7. | `Unauthorized of 'e
    (*

    401

    *)
  8. | `Bad_request of string
    (*

    400

    *)
  9. | `Method_not_allowed of string list
    (*

    405

    *)
  10. | `Unsupported_media_type
    (*

    415

    *)
  11. | `Not_acceptable of string
    (*

    406

    *)
  12. | `Unexpected_status_code of Cohttp.Code.status_code * content
    (*

    HTTP status code set by server is invalid or unsupported by resto

    *)
  13. | `Connection_failed of string
    (*

    Failure at one of the levels lower than HTTP (e.g., network)

    *)
  14. | `OCaml_exception of string
    (*

    Exception raised whilst decoding the result.

    *)
  15. | `Unauthorized_host of string option
    (*

    CORS-related error

    *)
  16. | `Too_many_redirects of string
    (*

    310

    *)
  17. | `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 = [
  1. | ('o, 'e option) generic_rest_result
  2. | `Unexpected_content_type of raw_content
  3. | `Unexpected_content of (string * Resto_cohttp.Media_type.Make(Encoding).t) * string
  4. | `Unexpected_error_content_type of raw_content
  5. | `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.

OCaml

Innovation. Community. Security.