package resto-cohttp-server

  1. Overview
  2. Docs

Module Server.MakeSource

Parameters

module Log : LOGGING

Signature

Sourcemodule Media_type : module type of struct include Resto_cohttp.Media_type.Make(Encoding) end
Sourcemodule Directory : module type of struct include Resto_directory.Make(Encoding) end
Sourcetype server

A handle on the server worker.

Sourcetype callback = Cohttp_lwt_unix.Server.conn -> Cohttp.Request.t -> Cohttp_lwt.Body.t -> Cohttp_lwt_unix.Server.response_action Lwt.t

A callback passed to Cohttp_lwt_unix.Server.make_response_action. Callbacks are exposed in order to give users a way to modify the arguments of the callback used to launch the server, or add some behaviour.

Sourceval init_server : ?cors:Resto_cohttp.Cors.t -> ?agent:string -> ?acl:Resto_acl.Acl.t -> media_types:Media_type.t list -> unit Directory.t -> server

Initializes the server

Sourceval resto_callback : server -> callback

resto_callback server is the default callback for resto. It can be used as is so the server simply handles requests. For example:

  let server = Server.init_server ~media_types directory in
  let callback = Server.resto_callback server in
  Server.launch server ~callback (`TCP (`Port port))

Which, as resto_callback is the default, is equivalent to:

  let server = Server.init_server ~media_types directory in
  Server.launch server (`TCP (`Port port))

Optionally, it can be transformed in order to provide additional functionalities. For example:

  let server = Server.init_server ~media_types directory in
  let callback = Server.resto_callback server in
  let auth_callback conn req bod =
    if check_auth req bod then
      callback con req bod
    else Lwt.return @@ `Response ... (* some form of response with 401 or 403 *)
  in
  Server.launch server ~callback:auth_callback (`TCP (`Port port)) >>= fun () ->
  ...
Sourceval launch : ?host:string -> server -> ?callback:callback -> Conduit_lwt_unix.server -> unit Lwt.t

launch server callback listening_protocol starts the given resto server initiating the listening loop using the listening_protocol. Each query will be treated using the given callback http handler.

Sourceval init_and_launch : ?host:string -> ?cors:Resto_cohttp.Cors.t -> ?agent:string -> ?acl:Resto_acl.Acl.t -> media_types:Media_type.t list -> unit Directory.t -> Conduit_lwt_unix.server -> unit Lwt.t

Initializes the server using the given arguments and starts it using resto_callback http handler. This is a condensed form of init_server, resto_callback, and launch.

Sourceval set_acl : server -> Resto_acl.Acl.t -> unit

configure the access list for this server

Sourceval shutdown : server -> unit Lwt.t

Kill an RPC server.

OCaml

Innovation. Community. Security.